Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 3053

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Tests for end-of-file on a file pointer</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.fclose.html">fclose</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.fflush.html">fflush</a></div>
 <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.feof" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">feof</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">feof</span> &mdash; <span class="dc-title">Tests for end-of-file on a file pointer</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.feof-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>feof</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$handle</code></span>
   )</div>

  <p class="para rdfs-comment">
   Tests for end-of-file on a file pointer.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.feof-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">handle</code></em></span>
     <dd>

      <p class="para">The file pointer must be valid, and must point to
a file successfully opened by  <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> or
 <span class="function"><a href="function.fsockopen.html" class="function">fsockopen()</a></span> (and not yet closed by
 <span class="function"><a href="function.fclose.html" class="function">fclose()</a></span>).</p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.feof-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> if the file pointer is at EOF or an error occurs
   (including socket timeout); otherwise returns <strong><code>FALSE</code></strong>.
  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-function.feof-notes">
  <h3 class="title">Notes</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    If a connection opened by  <span class="function"><a href="function.fsockopen.html" class="function">fsockopen()</a></span> wasn&#039;t closed
    by the server,  <span class="function"><strong>feof()</strong></span> will hang. To workaround this, see 
    below example:
    <div class="example" id="example-2357">
     <p><strong>Example #1 Handling timeouts with  <span class="function"><strong>feof()</strong></span></strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">safe_feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;&amp;</span><span style="color: #0000BB">$start&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">)&nbsp;{<br />&nbsp;</span><span style="color: #0000BB">$start&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br />&nbsp;return&nbsp;</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">/*&nbsp;Assuming&nbsp;$fp&nbsp;is&nbsp;previously&nbsp;opened&nbsp;by&nbsp;fsockopen()&nbsp;*/<br /><br /></span><span style="color: #0000BB">$start&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$timeout&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'default_socket_timeout'</span><span style="color: #007700">);<br /><br />while(!</span><span style="color: #0000BB">safe_feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$start</span><span style="color: #007700">)&nbsp;&amp;&amp;&nbsp;(</span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">$start</span><span style="color: #007700">)&nbsp;&lt;&nbsp;</span><span style="color: #0000BB">$timeout</span><span style="color: #007700">)<br />{<br />&nbsp;</span><span style="color: #FF8000">/*&nbsp;Handle&nbsp;*/<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div>
   </p>
  </div>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    If the passed file pointer is not valid you may get an infinite loop, because
     <span class="function"><strong>feof()</strong></span> fails to return <strong><code>TRUE</code></strong>.
    <div class="example" id="example-2358">
     <p><strong>Example #2  <span class="function"><strong>feof()</strong></span> example with an invalid file pointer</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;if&nbsp;file&nbsp;can&nbsp;not&nbsp;be&nbsp;read&nbsp;or&nbsp;doesn't&nbsp;exist&nbsp;fopen&nbsp;function&nbsp;returns&nbsp;FALSE<br /></span><span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">=&nbsp;@</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"no_such_file"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;FALSE&nbsp;from&nbsp;fopen&nbsp;will&nbsp;issue&nbsp;warning&nbsp;and&nbsp;result&nbsp;in&nbsp;infinite&nbsp;loop&nbsp;here<br /></span><span style="color: #007700">while&nbsp;(!</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">))&nbsp;{<br />}<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div>
   </p>
  </div>
 </div>

 
</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.fclose.html">fclose</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.fflush.html">fflush</a></div>
 <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>