A note on setting up execution memory and time limits for php scripts
When executing large amount of data through php scripts it is common facing errors like “Fatal error: Maximum execution time of 300 seconds exceeded..”. Also, sometimes uploading large files through php scripts you might face errors like “The uploaded file exceeds the upload_max_filesize directive in php.ini..” etc. etc.. The most possible reason for these kind of errors is the predefined default execution time and/or memory limit settings. In fact, in form of these kind of errors your system resources demand for more allocation of memory and/or time to complete operations asked.
To increase execution limit globally look for the following directives in php.ini file.
(To learn more about these directives see http://php.net/manual/en/ini.core.php)
post_max_size = 8M upload_max_filesize = 2M max_execution_time = 30 max_input_time = 60 memory_limit = 8M
(Generally these parameters are found in different lines of php.ini file so use ‘find’ utility of your text editor to find them, one at a time)
Change them to suit your needs. I made following changes to suit my needs:
post_max_size = 500M upload_max_filesize = 500M max_execution_time = 5000 max_input_time = 5000 memory_limit = 1000M
If you don’t have access to php.ini file, try setting up a .htaccess file with the following directives in it and place this file in your web server’s root folder. (If you want these settings to affect only a particular area of your website place this .htaccess file in that particular folder)
php_value post_max_size 500M php_value upload_max_filesize 500M php_value max_execution_time 5000 php_value max_input_time 5000 php_value memory_limit 1000
In case you are not able to modify ini.php on server or even you dont have permissions to setup a .htaccess file you may try to setup these values within your php script file. To make these settings take in effect your whole application just place them at the top of some common include file. In my case i set up them in my config.php file (only if needed) which i include at the top of every php file.
ini_set('post_max_size', '500M');
ini_set('upload_max_filesize', '500M');
ini_set('max_execution_time', 5000);
ini_set('max_input_time', 5000);
ini_set('memory_limit', 1000);
I hope that helps someone.
Possibly Related posts:
- Setting up a catch-all email forwarder and parsing emails using php
In one of my ongoing projects i had to set up a “catch-all” email parsing script. Here’s how it came out to be. What is...
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.






@pandu – try memory_limit, it should allocate memory required to handle the exceeding amount of data.
i create a tree structure using jquery, getting data from mysql.but when click on nodes, system executation time exceeds 30 seconds.
Any idea how to increase system time automatically based up on memory?
I know max_execution_time().Is any other method in php?..
reply fast…
Thank you