I'm really struggling with this issue, which is a little frustrating to me because it seems to be so simple in a Linux server. I have a Windows Azure Web App and I want to run "php artisan queue:listen" on the server continuously to take care of dispatched jobs. From what I read from the documentation, in Linux you just use Supervisor to run the command constantly and to revive it, in case it dies. From what I found online, Azure has a similar functionality called WebJobs where you can serve them a script to be ran and then decide whether it should run on a schedule or continuously (kinda like the Scheduler in Laravel). With this I have 2 questions.
1 - Is this the right solution? Place a script to run the command on a WebJob and have the WebJob run continuously?
2 - I'm not experienced in writing php scripts to run command lines, so all I can do is something like this:
echo shell_exec('php artisan queue:work');
Problem is this does not give me the output of the command (I don't see anything like the "processed" result that I see when I run the command by hand on my command console and a job is processed). It is important to me to be able to read the output of the command, because I want to be able to check the logs for errors in case something happens when a job isn't able to be processed. From the documentation shell_exec returns null in case an error is thrown so I'm completely clueless on how to deal with this.
Thank you so much in advance!
Instead of using shell_exec() you can directly upload .cmd file which includes your command php artisan queue:work, and then you can find the output log in WebJob Details page.
About how to do that, please check Ernesto's answer out.
For Azure you can make a new webjob to your web app, and upload a .cmd
file including a command like this.
php %HOME%\site\wwwroot\artisan queue:work --daemon
and defining that as a triguered and 0 * * * * * frecuency cron.
that way work for me.
For more information, please refer to Run Background tasks with WebJobs.
Related
I send mail as a cron job with Laravel. For this, when I want to use the last value I added in my resources/lang/de.json file in the mail blade template file(resources/views/mails/...blade.php), it gives an output as if such a value is not defined. However, if I use the same key in a blade file I created before, it works without any errors. In addition, the keys that I added to the same file (de.json) in the first time work without errors in the same mail blade file.
Thinking it's some kind of cache situation, I researched and found out that restarting the queue worker might fix the problem. However, both locally and on the server with ssh.
'php artisan queue:restart'
Even though I ran the command, there was no improvement.
Do you have any ideas?
Since queue workers are long-lived processes, they will not notice changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. https://laravel.com/docs/9.x/queues#queue-workers-and-deployment
but php artisan queue:restart will instruct all queue workers to gracefully exit after they finish processing their current job so that no existing jobs are lost. And I see a lot of issues with this command not to solve restart and deploy the worker.
So, Simplest way,
try to stop the worker manually (ctrl+C)
start the worker again with php artisan queue:work again.
might this help.
I’m trying to run a bash script in the background using Laravel. I’m currently using Symfony process to run it. However, there is a timeout and the user won’t be able to navigate the website until the script is done. The script doesn’t output anything. It simply runs other scripts and take the output and insert it into a database.
I have tried appending & at the end of the command as well as dev/null. No matter what I do the user can’t navigate away from the page until the script is done executing. If the user navigates away from the page, the script is stoped.
Regards,
Arron
You should use laravel queues, it is exactly what you want :
https://laravel.com/docs/5.8/queues
The easiest way is with a database, but if you are using it with redis, you can also use Laravel Horizon to monitor them : https://laravel.com/docs/5.8/horizon
Configure supervisord to run your script in the background. Google how to install and setup supervisor.
I'm having a PHP file which has some JS in it. I run a script on this file which will check if the date on a firebase database matches with the current date and if not update a few values. So I want this PHP file to run 24x7. I am completely new to heroku. Is it possible to do this on heroku or is there any other simpler solution ? Any help would be appreciated.
I don't see why not. You can set a worker process in your Procfile that will run a non web based process. In that PHP script you can set a timer to perform this action daily, and if were to crash for whatever reason, Heroku would restart the process.
Here's an explanation of how they work: https://devcenter.heroku.com/articles/background-jobs-queueing
I am looking for a way to link an azure scheduler or web job to the Laravel schedule.
My understanding is, to set up an Azure schedule I would need an end point to link to my Laravel, which I am not sure how to achieve that.
TL;DR
You can use the WebJobs under WebApps with an commandline script to trigger the Laravel scheduler.
Full reference
Azure providers WebJobs that can fire various triggers including Cron-like schedulers. In order to run the Laravel scheduler you need to trigger the schedule:run command every minute. For now I'll assume artisan lives in D:\home\site\wwwroot\artisan which is the default location for PHP based deployments.
Create a new file called runsched.cmd or anything else als long as it has the .cmd extension. Edit the file with notepad and add:
php %HOME%\site\wwwroot\artisan schedule:run
Save the file and go to the Azure portal.
Select you WebApp and find WebJobs under the application settings. Click Add and a sidepanel will appear.
Give the WebJob a name, for example LaravelSchulder and upload the runsched.cmd file from the first step.
Set Type to Triggered and make sure Triggers is set to Scheduled.
Now you can specify how often the command must be triggered. Even the portal says 'CRON Expression' the cron format is not the same as the Linux notation. If you set the expression to all asterisks as shown in the Laravel documentation you're command will be triggered every second, which is way too often for most applications. The correct CRON Expression is:
0 * * * * *
If you're Job looks something like this click OK.
The Laravel scheduler will now be triggered every minute. To verify that everything is working correctly you can trigger the job once yourself (Select the LaravelSchulder job and click Run) and check the job status. If Azure reports Failed under status check the logs and make sure you've entered the correct paths'
Hope that explains it.
Quick note: Microsoft likes to change Azure Portal on a regular basis, so any of these instructions may have changed by now.
Using Codeigniter 2.2.0 for my project. Is $this->input->is_cli_request() validation is necessary for a cron job?
It is recommended to protect your cronjob not to execute when someone type the URL in their browser. However if you don't have any problem running your cronjob invoked by anyone then can avoid this check.
Refer https://ellislab.com/codeigniter/user-guide/general/cli.html for more details.
It recommented to run cron jobs with command line.
There are many reasons for running CodeIgniter from the command-line, but they are not always obvious.
Run your cron-jobs without needing to use wget or curl
Make your cron-jobs inaccessible from being loaded in the URL by checking for $this->input->is_cli_request()
Make interactive "tasks" that can do things like set permissions, prune cache folders, run backups, etc.
Integrate with other applications in other languages. For example, a random C++ script could call one command and run code in your models!
More info read here
But you also can prevent calling from URL in your server.