Ways To Schedule Long Running Laravel Tasks Without Root And Privileged User

Me and my team are using a shared hosting service with a limited linux container (without root and privileged user) and we need to develop a new feature that involves long running tasks (> 600ms).

We thought of two possible solutions:

  1. Breaking apart the task, and via the frontend, make one separate http request to the server.

  2. Use bash screen to run a bash script with a infinite loop calling php artisan schedule:run (mimicking cronjob)

I don't feel very confortable with the first solution, moving server logic to the browser seens wrong in my opinion.

The second solution is only a supposition (not tested), we are not sure if the bash screen would randomly stop at any time.

What would be the least unstable way to achive our goal? Thx



Assuming you already explored this because you mention that a CRON would not be an option, but even unprivileged users can setup a CRON, which is the simplest solution in combination with the Laravel scheduler.

If an actual CRON using the scheduler is really out of the question I do think making an HTTP endpoint you could call from the browser is the next best thing. Just don't think an endpoint you can call from a browser that you can only call it from a browser ;)

Take for example (no affiliation but the first Google result). You can setup a CRON job there to call a URL to trigger those tasks on a CRON interval. Internally at my company called the "poor mans CRON" :)

I would agree that running a "screen" session is the most unreliable since on a server reboot those are not started again and if you "infinite loop" crashes it will not automatically restart.

If you go that route (or any CRON route) you can add some monitoring using for example (again no affiliation, Google). This allows you to define a CRON schedule and gives you a URL to call after the CRON finishes, if your CRON does not call that URL according to the CRON schedule you will be notified. Good to have as insurance.