Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: How to capture a timeout on a dio_read()?

I am using dio_read in PHP to capture input from a serial device (specifically the USB IR Toy v2 from Dangerous Prototypes).

Sometimes the input from the device is slow (10+ seconds). I'd like to timeout the dio_read, but not sure how.

If someone reading this post knows how, could you help point me in the right direction? thanks.

like image 739
Chris Drumgoole Avatar asked Feb 16 '13 04:02

Chris Drumgoole


2 Answers

dio_read on Windows (other platforms unknown) will not timeout if there is no data to read. There is no way to specify a timeout or do a non-blocking read on Windows. http://php.net/dio_read

like image 167
Sumit Avatar answered Nov 05 '22 11:11

Sumit


You can use dio_fctnl() to set the file descriptors flags to O_NONBLOCK or O_ASYNC

like image 36
torrentalle Avatar answered Nov 05 '22 10:11

torrentalle