It's seriously lame that there doesn't appear to be a good way to implement a queue listener for Laravel on IIS.
Best way to use queues on a Windows server
At a job I'm working at, they have Windows Server 2008 R2 machines. They are using PHP and Laravel however, and of course they would like to leverage the benifits of queues.
They don't really feel comfortable using Iron queues because data has to be send to other servers. So now I'm wondering how to do this. Seems the only possibility is to use a Redis queue, correct?
But even if I would use that, how would I run a queue listener, since Supervisord isn't available for Windows I believe.
Looking for a solution to this as well :/
After many years of frustration with the Windows Service Manger I found the Non-Sucking Service Manager. I just tested out using it to run the laravel queue service and it works great. I haven't bounced the system to make sure that it comes up on boot, but I have little doubt that it will.
In NSSM, the first tab has all the important configurations and I set it up as such:
Path: C:\Program Files (x86)\PHP\v7.0\php.exe
Startup Directory: C:\Users\daniel\projects\laravel-queue-test
Arguments: artisan queue:work
The remaining tabs are useful for configuring
- startup type: automatic/manual/disabled
- the user to run as
- service priority
- shutdown behaviour
- restarting
- I/O: stdin, stdout, stderr
- rotation of stdout/stderr files
- environment variables
Good Luck!
cheers, Daniel
Hi, this is really nice approach to problem.
But i think i stumbled upon issue that this solution potentially cause. In case if you use sqlsrv with windows authentication the process created by service is unable to access database. If you are forced to use windows authentication this is something to keep in mind.
Not sure how to approach this. Passing credentials to service will solve the problem but in corporate environment the passwords are changed very often and that means recreating the service everytime the password changes.
Other way around this would be to give service process access to database but i cant really tell how to make this happen.
It seems that using Scheduled Tasks is the only way to properly keep the queue worker going. Since there's no "Supervisor" application for Windows (or any equivalent that is built into Windows), setting a Scheduled Task to start the queue worker every 5 minutes and check-boxing "Do not start new instance if already running" has been working in production just fine.
However, I wish there was a better way to manage these Scheduled Tasks programatically. I attempted to use the command line schtasks.exe with PHP itself (using exec()), but you cannot import (via XML definition) or create tasks unless you specifically have your PHP script run with administrator level permissions, which again is a manual process and not what you'd want at all for production.
I've resorted to creating a Scheduled Task XML builder using PHP & Laravel (along with the package array-to-xml) that generates an XML file in your Laravel application and then you run one command on the server to import it. This also allows your scheduled tasks to be source controlled in your code base, allowing immediate visibility on what is running.
I hope this helps someone in the future.
Here's a gist:
https://gist.github.com/stevebauman/ddfb3b83e8981beec3a1ce7efdfd789f
@stevenbauman Yeah, works well. Thank you for the idea.
NSSM was a no-go for us since it hasn't been updated since 2017, and we need to redistribute it to end-users who may not appreciate the name.
We found this, which has so far worked great for running artisan queue:work commands:
https://github.com/ochinchina/supervisord
You can get Go on Windows and compile the supervisord.exe file. Here's an example config file we use (note the use of linux-style directory separators):
[inet_http_server]
port=127.0.0.1:9001
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=../php/php.exe -c ../php/php.ini artisan queue:work
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=C:/Program Files (x86)/my-app/storage/logs/queue.log
stopwaitsecs=30
directory=C:/Program Files (x86)/my-app
I compiled on Windows instead of cross-compiling on MacOS/Linux with
GOOS=windowsto be safe - a GitHub issue I read said it may be better to do that.
Hi. Thank you for the suggestion, I've tried it on Windows and it worked just fine but only from command line. I can not run it in background neither using default windows service or NSSM. It's just silent. How did you make it run permanently in background?
@azwrail did you ever find a solution?
For me worked perfectly NSSM to execute laravel queues
See my project to run Laravel queue as Windows native service. https://github.com/Litiano/Laravel-queue-for-windows
To set up a job supervisor for Laravel on Windows, you can use the Task Scheduler utility that comes with Windows. Here are the steps to follow:
-
Open the Task Scheduler by pressing the Windows key + R and typing "taskschd.msc" in the Run dialog box.
-
Click on the "Create Task" option in the "Actions" panel on the right-hand side.
-
Give your task a name and description in the "General" tab.
-
Switch to the "Triggers" tab and click the "New" button to create a new trigger. Here, you can set the schedule for your Laravel job to run. You can set the start time, end time, and the frequency of the job.
-
Switch to the "Actions" tab and click the "New" button to create a new action. In the "Program/script" field, enter the path to the PHP executable on your system (e.g., "C:\xampp\php\php.exe"). In the "Add arguments" field, enter the path to the Laravel artisan command for your job (e.g., "C:\xampp\htdocs\myproject\artisan queue:work --timeout=0").
-
Switch to the "Settings" tab and set any additional options you need for your task. For example, you can set the task to run whether the user is logged in or not.
-
Click "OK" to save your task.
Now your Laravel job is set up to run on a schedule on your Windows machine. You can monitor the status of your job and any errors it generates using the Task Scheduler's logging and monitoring features.
Please or to participate in this conversation.