How can PHP be optimized to ensure immediate output of data sent to a server socket?

To ensure immediate output of data sent to a server socket in PHP, you can use the `flush()` function after sending the data. This function forces PHP to send any output that has been buffered to the client or server immediately. By using `flush()`, you can optimize the performance of your PHP script when dealing with server sockets.

// Send data to server socket
socket_write($socket, $data, strlen($data));

// Flush the output buffer to ensure immediate data transfer
flush();