Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kabeda's avatar

How to run a cron job from server?

Hi, To feed my sitemap.xml file, I have to launch a cron procedure every day at 00:10. I saw this method https://laravel.com/docs/5.6/scheduling but from what I understand you have to use php artisan schedule:run and I don't like it since the server has to run artisan every minute and it's laravel, through the schedules that defines the launch time. I would like the cron of the server to execute my launch procedure through the execution of a php file which consults my db and fills in the xml by calling a controller already wrote. My concern is how to call this php file from the cron and what's the structure of this php file. For information, I filled my xml file before by launching a routine that called a route that used curl but now that we go through cloudflare, this method generates errors for me.

0 likes
7 replies
Tray2's avatar

If you use a linux host and register a cron job, it will run for you automatically, no need to use php artisan.

kabeda's avatar

Hi, Thanks @tray2 , My problem is how to call a laravel controller from php. So I just talk about cron as a key to find my solution.

Tray2's avatar

You can call it with a regular wget or a curl call. But if you are talking about a job, then you create the job that you start with a artisan call from your cron job script.

JussiMannisto's avatar

@kabeda Controllers are for handling HTTP requests. You should separate the action into a separate class. That way you can use it both in your controller and in an artisan command that you can can run as a cron job.

But it would be much easier (and make more sense imo) to use Laravel's scheduler to run the command. What's your objection to using it exactly?

kabeda's avatar

@JussiMannisto Using laravel scheduler seems to be called every minute. Will there not be a problem with the server?

JussiMannisto's avatar

@kabeda A performance problem? Absolutely not. It's negligible compared to all the other things the server has to do.

Please or to participate in this conversation.