You can use the Laravel scheduler for this.
https://laravel.com/docs/7.x/scheduling
->cron('* * * * *')->timezone('America/New_York');
The equicalent linux command would be something like:
0 0 30 10 ? 2020 /command
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everybody. I need a solution for my problem here. I have a website in which user can set some task to run at specific time. The tasks are about calling (POST) some API at specified time. For that i create a PHP Curl Script File for each Task and now want to run the Script at their time period. I googled around and found that there is some Cron job and Scheduler in Laravel but they are run forever at specified date and time. The thing i need is to Call script File at Time A and after TIme A my task should be terminated and do not run ever. I appreciate if any pros give me solution.
// find jobs that should start in the next minute
$jobs = Job::whereBetween('runtime',[now(),now()+addMinutes(1)])->orderBy('runtime')->get();
if(!$jobs) {
return; //nothing to do
}
foreach($jobs as $job) {
sleep($job->runtime-now()); // sleep for the difference between now and the runtime
// continue and perform curl task
}
There are some problems with this however. If more than one job can run per minute then you may be executing one at the time that a second should be executed. I don't know if you can guard for this. I mitigated this slightly by ordering the jobs in time order, however the Curl could take quite a few seconds to execute.
Please or to participate in this conversation.