0

In one of our laravel project in windows environment, we need a queue listener. So at the start we passed the following command in command prompt and that window remain opened.

C:\Apache24\htdocs\laravel\artisan queue:listen --timeout=240

But it's not a good move because if anyone mistakenly closed or after system update it may close. So we planned for background process with scheduler.

We run a batch file during system startup and every 1 hour. The batch has the following command.

start /MIN /B php C:\Apache24\htdocs\laravel\artisan queue:listen --timeout=240

But after a few days once we explored task manager we noted that there were many PHP CLI running in background process resulted in 100% process used. The System got slowdown. So we additionally added command to kill already running PHP CLI. The batch file was resembled like the given below commands.

taskkill /f /fi "imagename eq php.exe"
start /MIN /B php C:\Apache24\htdocs\laravel\artisan queue:listen --timeout=240

Now we need to run another background process with the interval of 1 minute. If it runs every minute then new PHP CLI background process will be started. If we kill all past PHP CLI background process it will kill already running PHP CLI for artisan queue.

So for this dependency what would be the best approach to resolve this issue.

Our main target is there won't be any orphaned PHP CLI background process running which consumes more memory.

gvgvgvijayan
  • 1,851
  • 18
  • 34

1 Answers1

0

I see here at last two options:

  1. Withing your PHP process check if there is already another one running. If it is - just long the info and bail. If it is not - continue the execution. This way you can keep the scheduler to try to start the process like every minute or so. If the previous process dies it will be restarted withing one minute.

  2. Use some kind of process supervisor. I found something like this for windows: winss. It is suppose to work similar to S6. It will than make sure there is only one instance running and will automatically restart it when it dies. Another supervisor is supervisord - it can be run through Cygwin. Take a look at this SO answer: Is there Windows analog to supervisord?

Aleksander Wons
  • 3,611
  • 18
  • 29