Home » Php » efficient way to run automatic tasks for more than 200 routes(tasks) laravel 5.8 php cron

efficient way to run automatic tasks for more than 200 routes(tasks) laravel 5.8 php cron

Posted by: admin February 25, 2020 Leave a comment

Questions:

there are multiple routes (300) that need to run every 2 hour. I have never done this kind of task and I really appreciate your help. after googling about it there are 4 ways for me to do it (given the time and the project):

1- add one cron job for every url manually in cpanel which I have realized since it’s laravel route it wouldn’t be possible. unless I make one php file for every url and curl the url in that php file and give direction to that in cron job.

php -q /home/yourCpanelUsername/public_html/filename1.php (curls one laravel route)
php -q /home/yourCpanelUsername/public_html/filename2.php (curls another laravel route)
php -q /home/yourCpanelUsername/public_html/filename3.php (and so on)

2- write multiple task schedule in laravel according to their documentation

3- make one and only one php file and give its address in the cron job and then in thet one use curl_multi as documented here or here or here

php -q /home/yourCpanelUsername/public_html/multicurlcron.php (curls multiple routes)

4- make one laravel task schedule and inside the function of it use curl multi nentioned above (number 3)
something like:

protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            // here is the part for curl multi code
        })->daily();
    }

which one is faster? and given that there are 300 routes, which way is more efficient?

thank you very much in advance

How to&Answers: