Re: Socket trouble

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To prevent the blocking and your CPU going up to 100% usages look into:
http://us2.php.net/manual/en/function.socket-select.php

For length of a string:
http://us2.php.net/manual/en/function.strlen.php


----- Original Message -----
From: René Fournier <m5@xxxxxxxxxxxxxxxx>
Date: Thursday, October 28, 2004 1:04 pm
Subject:  Socket trouble

> I'm having some trouble with my socket client. I would like it to 
> "notice" when the server is no longer there, and then reconnect. I 
> have 
> code for the reconnect, etc., but I can't figure out how to write 
> the 
> socket_read code so that it "notices" when the server is gone and 
> then 
> responds. Presently, my client just hangs (CPU goes to 100%, 
> nothing 
> happens.)
> 
> Here's my code:
> 
> while(($buf = socket_read($socket,1,PHP_BINARY_READ)) !== false) {
>                        	$data .= $buf;
>                        	if(preg_match("/TERMINATING/",$data)) {
>                                	$msg_recv = 1;
>                                	break;
>                                	}
>                        	}
> 
> The PHP docs on socket_read suggest how this might be done:
> 
> "Note: socket_read() may return a zero length string ("")  
> indicating 
> the end of communication (i.e. the remote end point has closed the 
> connection)."
> 
> Does this "end of communication" include cases when the socket 
> server 
> dies without gracefully disconnecting? How could my code check for 
> this 
> zero length string? Any help is much appreciated. Thanks!
> 
> ...René
> 
> ---
> René Fournier
> www.renefournier.com
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux