lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In my experiment on I use the Lua extension
for PHP which you can find only in the php SVN because it hasn't been
released yet. This way, PHP can control the resources used by Lua and
in case the values set for max_execution_time or memory_limit are
exceeded, trigger an error which you can catch to display a nice error
message and end the script correctly. If you are proficient in C, this
Lua extension for PHP needs some love I think:

Then there is my version which is probably all wrong since I am not an expert:

Bertrand Mansion

On Wed, Jun 9, 2010 at 10:35 AM,  <> wrote:
> Thanks you for all your answers, I managed to limit CPU time and memory using the "ulimit" command.
> But now there is a performance issue. I ran some tests on the current testing system and found out that launching the Lua parser (from my PHP script) takes around 0.02 seconds, almost exactly the time it takes to calculate the sine 100.000 times. Since the sandboxed Lua is supposed to be ran a few times for each PHP site parsed, this may cause serious performance problems (0.02s for intepreter + 0.02s for script = 0.04s, 0.04s * 10 = 0.4s, and this is just the Lua part, without any MySQL or PHP).
> Is there any possibility of running the interpreter all the time and just sending it commands which scripts to execute and then stream the output back to my PHP script? This would eliminate the need to start the interpreter again and again.
> Your help would really be appreciated,
> Lennart Moltrecht
> -----Ursprüngliche Nachricht-----
> Von: "Patrick Donnelly" <>
> Gesendet: Dienstag, 8 Juni, 2010 16:33
> An: "Lua list" <>
> Betreff: Re: [Sandboxed Lua] Limit execution time, loop iterations and memory usage
> On Tue, Jun 8, 2010 at 10:30 AM, Kurt Nordstrom
> <> wrote:
>> Also, look at the debugging hooks in the C API.
>> I'd be interested in seeing a good solution to limiting memory
>> over-allocation.
> There is a good solution, give Lua an allocator that has a limit on
> the amount of memory [1].
> [1]
> --
> - Patrick Donnelly

Bertrand Mansion