PHP Developers Cookbook (2nd Edition)

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

Категории