I writing php script that communicates with the server over unix local sockets.
1) connect
2) send msg with socket_write() (90% of time low-size blocks, 10% big size)
3) get the answer
4) close connection
Now, I have simple socket_write() implementation like suggested at comments from php manual “jean at briskula dot si 03-Feb-2011 03:00”
Seems its work fine on blocking mode, but I want to implement timeouts for socket_write, therefore I think (need) to use non-blocking mode, when socket_write() called.
Is there any advantages of blocking mode over non-blocking?
Is there a reason to realize timeouts?
How to realize them correctly?
Any examples?
Tried to write on a while circle, but got ===FALSE, maybe need to socket_select() every time before socket_write() called?
ps. this question also actual for socket_read() when reading answer from server
For a PHP (web-facing) script sending data to/receiving data from a backend system through sockets without the chance for other processing in the meantime (which is basically why you’d want to use non-blocking mode in the first place), there’s no sense in handling the complications that non-blocking mode causes.
So, stick with blocking mode.