Fixed bug #43782 (feof() does not detect timeout on socket)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@293364 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kalle Sommer Nielsen 2010-01-10 23:38:48 +00:00
parent e58b2f3c85
commit b4ceb970a7

View file

@ -44,10 +44,32 @@
<warning>
<simpara>
If a connection opened by <function>fsockopen</function> wasn't closed
by the server, <function>feof</function> will wait until a timeout has
been reached to return &true;. The default timeout value is 60 seconds.
You may use <function>stream_set_timeout</function> to change this
value.
by the server, <function>feof</function> will hang. To workaround this, see
below example:
<example>
<title>Handling timeouts with <function>feof</function></title>
<programlisting role="php">
<![CDATA[
<?php
function safe_feof($fp, &start = NULL) {
$start = microtime(true);
return feof($fp);
}
/* Assuming $fp is previously opened by fsockopen() */
$start = NULL;
$timeout = ini_get('default_socket_timeout');
while(!safe_feof($fp, $start) && (microtime(true) - $start) < $timeout)
{
/* Handle */
}
?>
]]>
</programlisting>
</example>
</simpara>
</warning>
<warning>