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);
}
To limit the maximum execution time use
set_time_limit($seconds).If set
$secondsto 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.