Laravel is one of the most popular PHP frameworks. With expressive syntax and ready-made packages, you can develop your websites rapidly from proof of concept to full-blown software-as-a-service.
Unlike Symfony, Laravel has a dedicated built-in package to set up and run cronjobs.
Once you schedule your tasks in your source code, you just need to set up one cronjob like this:
* * * * * cd /path-to-your-project && php artisan schedule:run > /dev/null 2>&1
Everything is okay, until it's not:
When your website grows, and you need to run a lot of scheduled tasks, just using the default task scheduler is not enough.
A much simpler way to run scheduled tasks is via the web.
Just create a route e.g. /cron/cleanup like this:
use App\Action\Backend\Cleanup;
use App\Http\Controllers\CronController;
use Illuminate\Http\Request;
Route::get('/cron/cleanup', function (Cleanup $cleanup, Request $request) {
if($request->input('key') !== 'SUPER_SECRET') {
return 'Hello there!';
}
ob_start();
$cleanup->run();
return ob_get_clean();
});
Now you can visit the cronjob URL
https://backend.example.com/cron/cleanup?key=SUPER_SECRET
with your browser to test your script.
If you still want to go with crontab, you can add it like this:
30 5 * * * curl https://backend.example.com/cron/cleanup?key=SUPER_SECRET
However, I'd recommend you to use a cronjob service like FastCron that offers:
Give it a try now, it's free!
Need help? Reach out to support@fastcron.com - we're happy to help.
See why 8,000+ website developers and their teams use FastCron to run their cronjobs 12 million times a day.
The reliable online cronjob service for your websites since 2009.