How To Limit Resources Used By A PHP Script

by lifeLinux on May 11, 2011

PHP supports the following resource limits directives in php.ini file. To limit resources used by a PHP script edit the file php.ini. Note that this change will affect all websites and PHP scripts on the server.

To find the location of php.ini, you can use the phpinfo() PHP function to find it. Create file with following content:

<?php
phpinfo();
?>


Sample outputs:

To edit php.ini, type the following command:

[[email protected] ~]# vi /etc/usr/local/etc/php.ini

Set maximum execution time of each script:

max_execution_time = 30

Set maximum amount of time each script may spend parsing request data

max_input_time = 30

Set maximum amount of memory a script may consume

memory_limit = 64M

Set maximum size of POST data that PHP will accept

post_max_size = 8M

Set maximum allowed size for uploaded files

upload_max_filesize = 8M

Disable/Enable HTTP file uploads (Disallow uploading unless necessary)

file_uploads = Off

Final, restart web server, example restart apache server, type the following command

[[email protected] ~]# /etc/init.d/httpd restart

Related Posts:

{ 1 trackback }

How To Increase PHP Memory Limit
May 11, 2011 at 4:39 am

{ 2 comments… read them below or add one }

den trang tri May 15, 2011 at 3:54 pm

please let me know why you chose exact value for these parameter ?which value is acceptable for a server with low resources ?

Reply

lifeLinux May 16, 2011 at 1:37 am

Don’t have exact value for these parameters. In this article, I give the above values because it is compatible with most scripts and it is drawn from my experience.
For a server with low resources, you need to know your PHP program needs many resources to run. Example you are running Joomla then minimum 16MB memory allocated to php.

Reply

Previous post:

Next post: