Sophie

Sophie

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

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>Set timeout period on a stream</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.stream-set-read-buffer.html">stream_set_read_buffer</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stream-set-write-buffer.html">stream_set_write_buffer</a></div>
 <div class="up"><a href="ref.stream.html">Stream Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.stream-set-timeout" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_set_timeout</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">stream_set_timeout</span> &mdash; <span class="dc-title">Set timeout period on a stream</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.stream-set-timeout-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>stream_set_timeout</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stream</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$seconds</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$microseconds</code><span class="initializer"> = 0</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   Sets the timeout value on <em><code class="parameter">stream</code></em>,
   expressed in the sum of <em><code class="parameter">seconds</code></em> and
   <em><code class="parameter">microseconds</code></em>. 
  </p>
  <p class="para">
   When the stream times out, the &#039;timed_out&#039; key of the array returned by
    <span class="function"><a href="function.stream-get-meta-data.html" class="function">stream_get_meta_data()</a></span> is set to <strong><code>TRUE</code></strong>, although no
   error/warning is generated.
  </p>
 </div>


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

    <dt>

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

      <p class="para">
       The target stream.
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The seconds part of the timeout to be set.
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The microseconds part of the timeout to be set.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-set-timeout-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure.
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.stream-set-timeout-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.3.0</td>
       <td>
        As of PHP 4.3, this function can (potentially) work on any kind of
        stream.  In PHP 4.3, socket based streams are still the only kind
        supported in the PHP core, although streams from other extensions
        may support this function.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-set-timeout-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4031">
    <p><strong>Example #1  <span class="function"><strong>stream_set_timeout()</strong></span> example</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fsockopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"www.example.com"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">80</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$fp</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Unable&nbsp;to&nbsp;open\n"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"GET&nbsp;/&nbsp;HTTP/1.0\r\n\r\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">stream_set_timeout</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_get_meta_data</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">'timed_out'</span><span style="color: #007700">])&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Connection&nbsp;timed&nbsp;out!'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

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

 
 <div class="refsect1 notes" id="refsect1-function.stream-set-timeout-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    This function doesn&#039;t work with advanced operations like
     <span class="function"><a href="function.stream-socket-recvfrom.html" class="function">stream_socket_recvfrom()</a></span>, use
     <span class="function"><a href="function.stream-select.html" class="function">stream_select()</a></span> with timeout parameter instead.
   </p>
  </p></blockquote>
  <p class="para">
   This function was previously called as
    <span class="function"><strong>set_socket_timeout()</strong></span> and later
    <span class="function"><a href="function.socket-set-timeout.html" class="function">socket_set_timeout()</a></span> but this usage is deprecated.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stream-set-timeout-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li class="member"> <span class="function"><a href="function.fsockopen.html" class="function" rel="rdfs-seeAlso">fsockopen()</a> - Open Internet or Unix domain socket connection</span></li>
   <li class="member"> <span class="function"><a href="function.fopen.html" class="function" rel="rdfs-seeAlso">fopen()</a> - Opens file or URL</span></li>
  </ul>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.stream-set-read-buffer.html">stream_set_read_buffer</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stream-set-write-buffer.html">stream_set_write_buffer</a></div>
 <div class="up"><a href="ref.stream.html">Stream Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>