I have this code, that uses mysqldump to backup mysql database. The problem is I'm getting this fatal error:
Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\pos\php\backupdb.php on line 13
Line 13 is the final line.
<?php
$backupFile = 'c:\\onstor'. date("Y-m-d-H-i-s") . '.sql';
$command = "mysqldump --opt -u root -p onstor > $backupFile";
system($command);
?>开发者_StackOverflow社区;
What do I do, I think the code is okay since I've tried it in command prompt and it worked. Is it bad that I have put the path to mysql/bin to the environment variables.
The problem, as the error message states pretty plainly, is that your script is running for too long. Scripts executing through a web server are not meant to run longer than a few seconds. You can change that using set_time_limit
, but what you should really do is let long running scripts run from the command line. Since the only thing you're doing is running a CLI command anyway, just ditch the PHP wrapper completely. Make it a shell script if necessary. Run this shell script regularly as a cron job/Windows Scheduler task (or whatever the Windows equivalent is called).
Your code looks okay. Dumping is taking lot of time. that's all. Read this Fatal error: Maximum execution time of 400 seconds exceeded. Do what is written there first and then look for any problem in your code.
The message say you reached out the 60 seconds excution time.
You can change it using the set_time_limit
function, i.e.:
set_time_limit(120); // 2 minutes
but I don't know why you would try to use mysqldump
in PHP, it seems dangerous to me.
精彩评论