My fwrite to a socket is not flushed, until the socket closes. How to change? I want it to flush after each fwrite.
I've tried:
1) flush()
2) fflush()
3) ob_implicit_flush(true);
None of those worked, I still had to quit php for my socket to receive the data.
Including some sample code, anything looks wrong?
while($clientSocket = socket_accept($this->serviceConnection))
{
while( $clientMessage = socket_read($clientSocket, 1024) )
{
echo 'Relaying message to server: ' . $clientMessage;
if( !fwrite($this->Connection, $clientMessage) )
echo 'Error writing to server';
fflush($this->Connection);
}
socket_close($clientSocket);
}
There is a function for that! fflush($rc)
Did you make sure you had the correct resource as the parameter?
edit
Okay. looking at your code you are using socket_* functions. You need to use fsockopen, fwrite, fflush, fsockclose. Your code should work the same, but you will be able to flush output. check out the example in the php manual for more details.