Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

Use nice or renice 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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.