The requirement is to set up a cron job that runs every 4 seconds. Since cron jobs can be executed only in minutes, I decided the trigger my job every minute and within the job, run it several time. Here's the code.
public function handle()
{
$dt = Carbon::now();
$counter = 60/4; //run the job every 4 seconds
do {
//logic goes here
time_sleep_until($dt->addSeconds(4)->timestamp);
} while ($counter-- > 0);
}
Cron job is scheduled as in crontab -e
*/1 * * * * /usr/bin/php /var/www/html/dashboard/artisan cronjob:pulldata
Job runs perfectly every 4 seconds when I execute it manually with the php artisan command. But, it executes only once a minute when it is triggered by the cronjob from crontab -e.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire