14.11 Getting Socket Status


You want to get some information about an existing high-level socket descriptor.

Technique

Use the socket_get_status() function:

 <?php $sock = fsockopen("www.slashdot.org", 80, $errstr, $errno, 30); if(!$sock) {     dir($errstr); } $res = fread($sock, 4000); var_dump(socket_get_status($sock)); fclose($sock); ?> 

Comments

socket_get_status() returns an array containing information about the specified socket descriptor. Currently, the array contains four entries:

  • timed_out (Boolean) ” True if the socket timed out while waiting for data

  • blocked (Boolean) ” True if the socket was blocked

  • eof (Boolean) ” True if no more data is available from the socket

  • unread_bytes (integer) ” Number of unread bytes in the socket buffer



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net