Home   Best Sellers   Blogging   Coding & Design   Technology   SEO   Travel & living   Career   Videos   Tips   Online tools     
Home  »     »     »     »  Increasing the PHP script execution time

Increasing the PHP script execution time

Thursday, December 2, 2010

How to Increase the PHP script execution time?

I am using a csv processing code , when i tried to import the csv content to the table using the php script, it take too much time and after that a download pop of the executing scripts name is showing...I think this is due to execution time problem. How to fix this?

Three ways we can solve this. : Scroll down for the solution.

Three ways we can solve this.

1) set_time_limit() function

usage : void set_time_limit ( int $seconds )

Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini.

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

The maximum execution time, in seconds. If set to zero, no time limit is imposed.

This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.

code to check safe mode and try the function:
if( !ini_get('safe_mode') ){

set_time_limit has another advantage, you can call it several times and it adds the time to the total script runtime. so you can use it in a loop and it doesn’t matter how many iterations you have, you set only the time per iteration.

########### ###########

2) ini_set() function

string ini_set( string $varname , string $newvalue )

The php function ini_set sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

Usage ini_set( "max_execution_time" , "55" )

########### ###########

3) Modifying `max_execution_time' value in PHP configuration(php.ini) file

This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.

options 1 and 2 are using for temporarily purpose and will persist until the scripts execution completed ie, The configuration option will keep this new value during the script's execution, and will be restored at the script's ending. Option 3 is for permanent purpose.

More info:

Share this!

How to link to this page?
If you wish to link to this page from your website, simply Copy and paste the above HTML code to your web page. It will appear on your page as:
Increasing the PHP script execution time.

comments powered by Disqus

This Weeks 7 Popular Posts

Subscribe to Recent Posts by Email
Stay connected to CROZOOM with regular Email notices of new Techie articles and IT Jobs. Updates will be delivered to your Inbox as soon as they are posted online.

Enter Your Email Address:  

Delivered by FeedBurner   RSS Feed

Search this Blog   

Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »