Answer the question
In order to leave comments, you need to log in
How to run cron task on server startup only after Mysql start?
I have a php file in which an infinite loop is implemented, the fact is that when @reboot the task is executed before MySQL starts, the PHP file is executed, at the time of accessing which MySQL does not work and an error pops up, which then loops, even if MySQL has already risen all the same, until you restart the PHP file, there will be this error "PHP Warning: mysqli::query(): invalid object or resource mysqli" The
question is how to perform a task of such a plan:
/opt/php70/bin/php /var/ www/user/data/www/site.ru/mail.php when the server starts, only after MySQL starts up or it may be possible to organize an infinite loop in the PHP file in such a way that when it starts it does not get an error at start ?
The cycle is simple:
<?php
$mailing = new Mailing();
if ($mailing->true) {
while(1==1) {
$mailing->mail_pr_queue();
sleep(5);
}
}
?>
Answer the question
In order to leave comments, you need to log in
Perhaps it’s better to do this not with cron, but with systemd unit and timer. And register the dependency so that only after mysql starts.
in
@reboot mysqld cron && my_task.php
this is the concept. kick mysql from autostart
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question