PHP Conference Japan 2024

LuaSandbox::setMemoryLimit

(PECL luasandbox >= 1.0.0)

LuaSandbox::setMemoryLimit設定 Lua 環境的記憶體限制

說明

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

設定 Lua 環境的記憶體限制。

如果超過此限制,則會拋出 LuaSandboxMemoryError 例外。

參數

limit

記憶體限制,單位為位元組。

返回值

無返回值。

範例

範例 #1 呼叫 Lua 函式

<?php

// 建立新的 LuaSandbox
$sandbox = new LuaSandbox();

// 設定記憶體限制
$sandbox->setMemoryLimit( 50 * 1024 * 1024 );

// 執行 Lua 程式碼
$sandbox->loadString( 'local x = "x"; while true do x = x .. x; end' )->call();

?>

上述範例將輸出類似以下的內容

PHP Fatal error:  Uncaught LuaSandboxMemoryError: not enough memory

另請參閱

新增註釋

使用者貢獻的註釋

此頁面沒有使用者貢獻的註釋。
To Top