When using socket communication in PHP, do I need to confirm if a message has been successfully received after sending each message? Or would the transport layer (TCP) take care of error detection and correction, ensuring successful delivery of any sent messages?
You can safely believe that the data has been successfully received if the php function does not point out any specific error.
"TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer" , so that's a yes to the latter.
You don't need to worry about such things on this level. Once you write the data into an open socket, you can be sure that it will eventually arrive correctly (assuming there is a route between the end points). What you should take care of is the return values of socket functions. Check all return values of the socket_*
functions for a reliable communication.
TCP handles error detection and correction as far as it goes. There isn't really such a thing as ensuring successful delivery (cf. backhoe fade), so there's some level at which you need to take into account the possibility that a message will not be delivered.