I have a customer who is getting an error related to a script timeout. I've included the code below, but i think the issue is that the timeout needs to be extended.
Is this something I can set in the code, or does it have to be set by the web host (GoDaddy)?
Fatal error: Maximum execution time of 30 seconds exceeded in D:\hosting\123\html\siteame\wp-content\plugins\myplugin\myplugin.php on line 170
The code at that point is:
function my_copy_recurse($src,$dst){
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) )
{
if (( $file != '.' ) && ( $file != '..' ))
{
if ( is_dir($src . '/' . $file) ) {
my_copy_recurse($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
} //THIS IS LINE 170
}
closedir($dir);
}
If you've hosted your site on GoDaddy, Windows Hosting and are using WordPress, sooner or later you will face the max execution time out problem. I faced this problem for quite some time and looked aroung google, hitting my head. If you've faced the same series of problems as below:
this post is for you>
upload info.php to the root of your hosting. Now browse to http://yourhost/info.php. Whatever loads up on the screen is the PHP config. Look for Loaded Configuration File and note down its value. IN my case it is C:\PHP5\php.ini. We need all this information in our custom PHP5.ini file but its too much info to copy and format, so we will copy GoDaddy's default file and edit it as necessary.
fire your text editor and create the following file: getconfig.php
<?php copy('C:\PHP5\php.ini'*, 'PHP5.ini'); echo('finally'); ?>
(replace * with whatever path shows up in Loaded Configuration File)
copy file getconfig.php to badaddy and now browse to http://yourhost/baddaddy/getconfig.php.
Once you see "finally" written on screen, go back to the filemanager in GoDaddy Control Panel, goto baddaddy folder and you will see a new file PHP5.ini appear there. Download this file. This is a copy of GoDaddy Settings.
Make whatever changes you need to(just know what you're changing, I am not a PHP expert, so I cannot be responsible if you screw up something). For my problem, I changed the max_execution_time = 30 to max_execution_time = 1200.
Upload the edited file to the root of your application and back in the GoDaddy Control Panel, IIS Management, hit Recycle App Pool, and then WAIT FOR A WHILE (20 minutes)
browse back to http://yourhost/info.php to confirm the new settings are in place
IMPORTANT ** IF you see a "500: Internal Server Error" on your GoDaddy WordPress Blog after doing all this, 12. Change the log_errors from log_errors = On to log_errors = Off in the PHP5.ini you just edited and re-upload, recycle app pool and wait. The 500 error pop up if the log file cannot be found.
I AM NO PHP EXPERT but this thing worked for me, the blog still loads slow but I have not seen any "Fatal Error: 30 second timeout" since then.
Depending on what settings your host has allowed you may be able to use set_time_limit() pass to it in seconds how long you want it to spend before it times out (use 0 for infinite). E.g:
GoDaddy may have blocked this though so if it doesn't work try contacting them
By setting "max_execution_time = 600" in "php.ini" file worked for me.
Change your code to this :
To limit the maximum execution time use
set_time_limit($seconds)
. If set$seconds
to zero, no time limit is imposed. So just addset_time_limit(0)
at the beginning of the script and script will work till the end. But if user's browser disconnects due to browser timeout your script could be halted, so you need to addignore_user_abort(true)
at the beginning of the script to ignore it and work exactly till the end of the script.Girish's answer is incomplete. What has to be included in info.php? You may use simple update provided at: fix-for-fatal-error-maximum-execution-time-30-seconds-exceeded-wordpress