PHP-Serial icon indicating copy to clipboard operation
PHP-Serial copied to clipboard

Calling deviceOpen hangs up the PHP process

Open stollr opened this issue 4 years ago • 0 comments

I am using Linux version 4.19.0-14-amd64 and PHP 7.4 and try to access a GSM modem.

When fopen('/dev/ttyS0', 'r+b') is called within deviceOpen() method PHP is blocking and does not resume. I have searched around and found out that people who use C open serial ports with O_RDWR | O_NDELAY mode (see here).

In PHP there is an undocumented flag n, which makes fopen using non-blocking mode. Here are my sources:

  • https://bugs.php.net/bug.php?id=61645
  • https://www.php.net/manual/en/function.fopen.php#125030 (comment by php-manual at merlindynamics dot com)

When I call $serial->deviceOpen('r+bn') with the "n" flag, my code works ;-)

I hope this will help somebody.

stollr avatar May 11 '21 15:05 stollr