While I receive data in my iOS application (some data is received, but not all), I intentionally terminate the application and socket_writefreezes on the server. Here is the relevant code:
error_log("start write");
$sent = socket_write($client, $string, $length);
error_log("end write");
I get a message "start write"in my error log, but it just keeps hanging until I restart the php program.
I tried to set a timeout, but then I tried to download a large file, and it looks like it was disconnected before the download completed. I thought that the timeout is a period of inactivity, and not the total time for which the client is connected. In any case, any help is appreciated. I assumed that it socket_writewill return if the socket is disconnected, but I am mistaken or the code. Thanks for any help.
EDIT
Basically, I need to know when the client disconnected. It looks like fwrite, socket_send, and socket_write all freeze when the client disables mid-write and lock mode. If I turn off the lock mode, my code is as follows:
function send_data($client, $string)
{
$length = strlen($string);
socket_set_nonblock($client);
while(true)
{
$sent = socket_write($client, $string, $length);
//OR - $sent = socket_send($client, $string, $length, 0);
if($sent === FALSE)
{
error_log("false");
return;
}
if($sent < $length)
{
$string = substr($string, $sent);
$length -= $sent;
}
else
return;
}
}
The problem is that $sent === FALSEwhen the client disconnects, and also when they are temporarily unavailable, which turned out to be after sending the first few bytes, thus not sending a whole line.