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:
Breaking apart the task, and via the frontend, make one separate http request to the server.
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
Answer
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 https://www.easycron.com/ (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 https://healthchecks.io/ (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.
Related Questions
- → Database Record created_at Time Randomly Changes
- → npm is putting all dependencies and sub-dependecies int he same folder
- → Laravel 5.2 not working with vagrant homestead php 7
- → Can't add cron task in Laravel 5.0.5 on linux server
- → Node.js Split large file into parts and iterate over the parts
- → Laravel - Connection could not be established with host smtp.gmail.com
- → Redirect Each Page of Old Domain to Same Page URL on the New Domain
- → October CMS - Cannot edit pages in backend - http status 403
- → The Laravel View is Not Working On Linux Server
- → How to get a value in an array that's in a list of arrays in javascript
- → Beanstalkd to start when the system starts up or reboots , how to uncomment "START yes" on Centos
- → Vagrant with homestead and Linux boxes
- → Only one route not returning anything on live Laravel site, works on local sites