« LuaSandbox::setCPULimit
LuaSandbox::unpauseUsageTimer »

LuaSandbox::setMemoryLimit

(PECL luasandbox >= 1.0.0)

LuaSandbox::setMemoryLimit — Set the memory limit for the Lua environment

説明

public function 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

参考

関連キーワード:
LuaSandbox   limit   memory   environment   setMemoryLimit   sandbox   setCPULimit   LuaSandboxMemoryError   Fetch   usage   unpauseUsageTimer   luasandbox   Sets   exceeded   exception   thrown   Memory   bytes   Calling   create   code   loadString   local   while   call
関連する関数・ページ:
luasandbox.setcpulimit   luasandbox.getmemoryusage   luasandbox.getpeakmemoryusage   book.luasandbox   class.luasandbox   luasandbox.getcpuusage