As I understand, it is possible to create a nonblocking network socket in PHP 5.x.
But what happens if a script sends several long messages using the same nonblocking socket as follow:
socket_write($socket, $string1, $length);
socket_write($socket, $string2, $length);
socket_write($socket, $string3, $length);
socket_write($socket, $string4, $length);
Are these messages queued (on the sender/receiver side?) or is it possible that the receiver gets parts of different messages because they sent “parallel”?
For example: Is is possible that the receiver gets 10 bytes of $string1, then 30 bytes of $string2, then another 25 bytes of $string1 … and so on….
It depends on the protocol that the socket is using. See socket_create for the possible types of sockets. The main types are UDP and TCP:
To answer your question directly, TCP sockets will guarantee in-order delivery, whereas UDP sockets will not.