Re: How to tell if a socket is connected

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

 



Adam Zey wrote:

> Michael W. wrote:
>> Hello,
>>   Can any of you tell me how to tell whether a socket (from fsockopen())
>>   is
>> connected or not? Specifically, whether the remote server has closed the
>> connection? Stream_get_meta_data() does not do it; in my tests, its
>> output does not change even when the server closes the stream.
>> 
>> Thank you,
>> Michael W.
> 
> If it is a network socket, and the remote end disconnected unexpectedly
> (which you MUST assume is a possibility), then the only way to find out
> if the connection is still open is by SENDING data. Just trying to read
> it won't cut it.
> 
> The thing to understand is that when a remote client/server disconnects,
> it normally safely closes the socket and notifies you. But an abrupt
> disconnection (Something crashes, loses connectivity, etc) sends no such
> thing. The only way to find out that a connection is really lost is to
> write some data and see if it times out or not.
> 
> Regards, Adam Zey.

How can I tell whether the write timed out? Does fwrite() return false, or
do I have to check for the 'timed_out' flag in the return of
stream_get_meta_data()?

Thanks a lot,
Michael W.

-- 
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