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);
?>
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).