在PHP中执行socket_write后刷新套接字

I have the following code:

foreach ($this->_queue as $header)
{
    $result = socket_write($this->_socket, $header, strlen($header));
    if (!$result)
    {
        // check error here if result was false
    }
}
socket_close($this->_socket);

This code works fine-ish in that it will generally reach the third iteration of the foreach, after which it breaks out completely (doesn't even reach the socket_close($this->_socket) line).

I suspect that I need to do something like flush the socket (force it to write and then clean itself or something) but I have not found anywhere that indicates if this is possible.

Would it be better to simply open and close a socket for each iteration through $this->_queue?