Typical PHP socket functionality is synchronous, and halts the thread when waiting for incoming connections and data. (eg.
How do I do the same asynchronously? so I can respond to data in a data received event, instead of polling for data, etc.
Yup, that's what
socket_set_nonblock()is for. Your socket interaction code will need to be written differently, taking into account the special meanings that error codes 11,
EWOULDBLOCK, and 115,
Here's some somewhat-fictionalized sample code from a PHP sync socket polling loop, as requested: