<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.luasandbox.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'luasandbox.setcpulimit.php',
    1 => 'LuaSandbox::setCPULimit',
    2 => 'Set the CPU time limit for the Lua environment',
  ),
  'up' => 
  array (
    0 => 'class.luasandbox.php',
    1 => 'LuaSandbox',
  ),
  'prev' => 
  array (
    0 => 'luasandbox.registerlibrary.php',
    1 => 'LuaSandbox::registerLibrary',
  ),
  'next' => 
  array (
    0 => 'luasandbox.setmemorylimit.php',
    1 => 'LuaSandbox::setMemoryLimit',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/luasandbox/luasandbox/setcpulimit.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="luasandbox.setcpulimit" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">LuaSandbox::setCPULimit</h1>
  <p class="verinfo">(PECL luasandbox &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">LuaSandbox::setCPULimit</span> &mdash; <span class="dc-title">Set the CPU time limit for the Lua environment</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-luasandbox.setcpulimit-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>LuaSandbox::setCPULimit</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.float.php" class="type float">float</a></span>|<span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></span> <code class="parameter">$limit</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="simpara">
   Sets the CPU time limit for the Lua environment.
  </p>
  <p class="simpara">
   If the total user and system time used by the environment after the call
   to this method exceeds this limit, a <span class="classname"><a href="class.luasandboxtimeouterror.php" class="classname">LuaSandboxTimeoutError</a></span>
   exception is thrown.
  </p>
  <p class="simpara">
   Time used in PHP callbacks is included in the limit.
  </p>
  <p class="simpara">
   Setting the time limit from a callback while Lua is running causes the
   timer to be reset, or started if it was not already running.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    On Windows, the CPU limit will be ignored. On operating systems that do
    not support <strong><code>CLOCK_THREAD_CPUTIME_ID</code></strong>, such as FreeBSD
    and Mac OS X, wall-clock time rather than CPU time will be limited.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-luasandbox.setcpulimit-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt><code class="parameter">limit</code></dt>
    <dd>
     <span class="simpara">
      Limit as a <span class="type"><a href="language.types.float.php" class="type float">float</a></span> in seconds, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> for no limit.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-luasandbox.setcpulimit-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="simpara">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-luasandbox.setcpulimit-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-1">
   <p><strong>示例 #1 Calling a Lua function</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// create a new LuaSandbox<br /></span><span style="color: #0000BB">$sandbox </span><span style="color: #007700">= new </span><span style="color: #0000BB">LuaSandbox</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// set a time limit<br /></span><span style="color: #0000BB">$sandbox</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setCPULimit</span><span style="color: #007700">( </span><span style="color: #0000BB">2 </span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Run Lua code<br /></span><span style="color: #0000BB">$sandbox</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadString</span><span style="color: #007700">( </span><span style="color: #DD0000">'while true do end' </span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">call</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>以上示例的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">PHP Fatal error:  Uncaught LuaSandboxTimeoutError: The maximum execution time for this script was exceeded</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-luasandbox.setcpulimit-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="luasandbox.getcpuusage.php" class="methodname" rel="rdfs-seeAlso">LuaSandbox::getCPUUsage()</a> - Fetch the current CPU time usage of the Lua environment</span></li>
   <li><span class="methodname"><a href="luasandbox.setmemorylimit.php" class="methodname" rel="rdfs-seeAlso">LuaSandbox::setMemoryLimit()</a> - Set the memory limit for the Lua environment</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>