PHP Execution Time Limit Setting

Recently I had a little problem stump me while designing the back end of a commercial site. The back end user interface uploads rather large image files so that the files can be processed for ‘Zoomify’( a fast way of showing a highly detailed zoomable image). After making sure the process was secure, I also needed to change a few settings in the PHP ini file in order for the system to allow files sizes of over 2 megs. All was working great on the local testing server. However, once the site was in the “live” pre production mode, the large file sizes would return an error. I knew it was not the file size issue because I had already compensated for that with the ini_set(“memory_limit”,”64M”); line.

Setting the PHP Execution Time Limit

What tipped me off to the problem was the fact that, every once in a while the file would upload with no error. That is when I realized it was not only a “memory limit” issue but also a timing issue.
Settings we do not often deal with are easy to forget about and that was the case this time. Once I remembered to reset the max_execution_time to the appropriate amount of seconds, the files uploaded just fine.

As mentioned above, the maximum execution time limit is set in the php.ini file. The line of code in the php.ini file is:

max_execution_time = 30 ; Maximum execution time of each script, in seconds

It is generally not wise to make this change in the php.ini file itself unless you have a very good reason. The preferred way would be to make the required change in execution time for the particular script you happen to be running only. This gives you better control over site operations and security.

Simply place an ini file setting within the file that executes the script which is causing a delay ( in my case the file upload ). The line code looks like this:

set_time_limit ( 60 ) ;

With this little line of code in you PHP script, you are now afforded 60 seconds of time to run your program. You can adjust the seconds as you wish by simply changing the number. I hope this helps!

Leave a Reply

Your email address will not be published.