array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'luasandbox.setmemorylimit.php', 1 => 'LuaSandbox::setMemoryLimit', 2 => 'Set the memory limit for the Lua environment', ), 'up' => array ( 0 => 'class.luasandbox.php', 1 => 'LuaSandbox', ), 'prev' => array ( 0 => 'luasandbox.setcpulimit.php', 1 => 'LuaSandbox::setCPULimit', ), 'next' => array ( 0 => 'luasandbox.unpauseusagetimer.php', 1 => 'LuaSandbox::unpauseUsageTimer', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/luasandbox/luasandbox/setmemorylimit.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

LuaSandbox::setMemoryLimit

(PECL luasandbox >= 1.0.0)

LuaSandbox::setMemoryLimitSet the memory limit for the Lua environment

说明

public LuaSandbox::setMemoryLimit(int $limit): void

Sets the memory limit for the Lua environment.

If this limit is exceeded, a LuaSandboxMemoryError exception is thrown.

参数

limit

Memory limit in bytes.

返回值

没有返回值。

示例

示例 #1 Calling a Lua function

<?php

// create a new LuaSandbox
$sandbox = new LuaSandbox();

// set a memory limit
$sandbox->setMemoryLimit( 50 * 1024 * 1024 );

// Run Lua code
$sandbox->loadString( 'local x = "x"; while true do x = x .. x; end' )->call();

?>

以上示例的输出类似于:

PHP Fatal error:  Uncaught LuaSandboxMemoryError: not enough memory

参见