mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
e58b2f3c85
commit
b4ceb970a7
1 changed files with 26 additions and 4 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue