downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.time-nanosleep.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.time-nanosleep.php',
   
1 => 'time_nanosleep',
  ),
 
'up' =>
  array (
   
0 => 'ref.misc.php',
   
1 => 'Misc. Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.sys-getloadavg.php',
   
1 => 'sys_getloadavg',
  ),
 
'next' =>
  array (
   
0 => 'function.time-sleep-until.php',
   
1 => 'time_sleep_until',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.time-nanosleep" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">time_nanosleep</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">time_nanosleep</span> &mdash; <span class="dc-title">Delay for a number of seconds and nanoseconds</span></p>

 </div>
 
 <a name="function.time-nanosleep.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b>time_nanosleep</b></span>
    ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$seconds</tt></span>
   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$nanoseconds</tt></span>
   )</div>

  <p class="para rdfs-comment">
   Delays program execution for the given number of
   <i><tt class="parameter">seconds</tt></i>
 and <i><tt class="parameter">nanoseconds</tt></i>
.
  </p>
 </div>


 <a name="function.time-nanosleep.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">seconds</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Must be a positive integer.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">nanoseconds</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Must be a positive integer less than 1 billion.
      </p>
     </dd>

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


 <a name="function.time-nanosleep.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
  </p>
  <p class="para">
   If the delay was interrupted by a signal, an associative array will be
   returned with the components:
   </p><ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      <i>seconds</i> - number of seconds remaining in
      the delay
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <i>nanoseconds</i> - number of nanoseconds
      remaining in the delay
     </span>
    </li>
   </ul><p>
  </p>
 </div>

 
 <a name="function.time-nanosleep.changelog"></a><div class="refsect1 changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   </p><table class="doctable informaltable">
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">5.3.0</td>
       <td align="left">
        This function is now available on Windows platforms.
       </td>
      </tr>

     </tbody>
   
   </table>
<p>
  </p>
 </div>


 <a name="function.time-nanosleep.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>time_nanosleep()</b> example</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Careful!&nbsp;This&nbsp;won't&nbsp;work&nbsp;as&nbsp;expected&nbsp;if&nbsp;an&nbsp;array&nbsp;is&nbsp;returned<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">time_nanosleep</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">500000000</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Slept&nbsp;for&nbsp;half&nbsp;a&nbsp;second.\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;better:<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">time_nanosleep</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">500000000</span><span style="color: #007700">)&nbsp;===&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Slept&nbsp;for&nbsp;half&nbsp;a&nbsp;second.\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;And&nbsp;this&nbsp;is&nbsp;the&nbsp;best:<br /></span><span style="color: #0000BB">$nano&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">time_nanosleep</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">100000</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$nano&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Slept&nbsp;for&nbsp;2&nbsp;seconds,&nbsp;100&nbsp;microseconds.\n"</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;(</span><span style="color: #0000BB">$nano&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Sleeping&nbsp;failed.\n"</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;(</span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$nano</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seconds&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$nano</span><span style="color: #007700">[</span><span style="color: #DD0000">'seconds'</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$nanoseconds&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$nano</span><span style="color: #007700">[</span><span style="color: #DD0000">'nanoseconds'</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Interrupted&nbsp;by&nbsp;a&nbsp;signal.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Time&nbsp;remaining:&nbsp;</span><span style="color: #0000BB">$seconds</span><span style="color: #DD0000">&nbsp;seconds,&nbsp;</span><span style="color: #0000BB">$nanoseconds</span><span style="color: #DD0000">&nbsp;nanoseconds."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

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


 <a name="function.time-nanosleep.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.sleep.php" class="function" rel="rdfs-seeAlso">sleep()</a> - Delay execution</li>
    <li class="member"><a href="function.usleep.php" class="function" rel="rdfs-seeAlso">usleep()</a> - Delay execution in microseconds</li>
    <li class="member"><a href="function.time-sleep-until.php" class="function" rel="rdfs-seeAlso">time_sleep_until()</a> - Make the script sleep until the specified time</li>
    <li class="member"><a href="function.set-time-limit.php" class="function" rel="rdfs-seeAlso">set_time_limit()</a> - Limits the maximum execution time</li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites