I have a pretty standard LAMP setup on my Debian VPS. The VPS has 512MB of ram, and I've assigned 128MB in my php.ini for php.
If I create a script with an infinite loop in it the VPS pretty much comes to a standstill (SSH stops being responsive etc..)
I was wondering if there's a way to lower PHP's priority or something like that so that bad scripts can't interfere too much with the server.
Thanks, John.
You actually have two options here, depending on how you run this. One solution is to limit the runtime of PHP scripts--that is, you can have a PHP script terminate automatically based on its actual run time.
If you're running this from a web server (Apache, Lighttpd, etc.), you can use the max_execution_time parameter. By default, this is 30 seconds. If you're running this from the CLI, use the set_time_limit function.
Another solution is to use something such as
monit
to monitor the load and CPU usage of the PHP process and kill it if it gets to a specified level.Hope this helps; although it might be a good idea to eliminate these kinds of logic errors from your scripts entirely.
Use
nice
orrenice
on the webserver process if PHP is running as a module (e.g. mod_php). This will allow PHP to use more resources when they are available, but will prioritize other processes which may need them.I should add that this is only for Linux, and maybe UNIX.