Re: How to make a PHP Socket client crash-proof?
| From: | René Fournier | Date: | Fri, 10 Dec 2004 18:09:18 +0000 |
| Subject: | Re: How to make a PHP Socket client crash-proof? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-203943@lists.php.net to get a copy of this message | ||
I managed to solve the problem with the socket client hanging when the Server "disappears".
Actually, it is not hanging. What I discovered is that once the other end of the connection drops, it starts/continues reading on that socket ad infinitum. (I put a little counter in it, and can watch it count up). What I did to stop detect a gone connection, and then restart the socket, isn't elegant, doesn't use a socket_select() or non-blocking, but it DOES work.
$i = 0;
while(($buf = socket_read($socket,1,PHP_BINARY_READ)) !== false) {
echo $i." >> \n";
$i++;
$data .= $buf;
if(preg_match("/EOF/",$data)) {
$msg_recv = 1;
break;
}
if($i>10000) {
$connect = false;
break;
}
}
Still, one day I would like to re-architect this. Seems a bit hackish.
...Rene
On 9-Dec-04, at 1:19 PM, Richard Lynch wrote:
Have you completely eliminated the possiblity of having a second, independent, completely unrelated client/socket which is used to *SEND* data to the server? client_get <------ server client_send -------> server They can both use your local database to share data, to whatever degree you deem necessary, but having one-way sockets for two different scripts is way more easier than trying to get a two-way socket to work, in my (limited) experience. If you MUST push forward with a two-way socket, try to determine the state of the world inside your infinite loop. Why aren't you breaking out of that loop? Can you do *anything* to break out? I suspect that once you have started SENDING data to the server, it's going to just keep waiting for you to send more. How do you signal the end of your data to be sent? Does the server understand that signal? -- Like Music? http://l-i-e.com/artists.htm...René --- René Fournier www.renefournier.com