Home > OS >  How to keep a process running in the background? - Laravel
How to keep a process running in the background? - Laravel

Time:03-05

I'm using the php-imap package and I want to listen for incoming emails.

The way to achieve this with php-imap is to call an idle() function, like this:

$emailFolder->idle(function (Message $email){
   // dispatch event
});

The problem is that the idle() function never finishes running and the rest of the code is never executed.

I need to call the idle() function for each user, since I must listen for incoming emails for all of my users.

T've tried to set up a job for each user and dispatch it to a queue, but then the job never ends (and since the numbers of users changes, the number of workers must change), and I can't find a way to stop the job when needed.

I also need a way to stop the execution of the idle() function for a specific user, for example if the user deletes its account.

Is there a way to run that piece of code in the background, without it interfering with the code execution, with the possibility to stop the execution of a specific instance of the process?

CodePudding user response:

I found a solution.

Here it is: https://github.com/Webklex/php-imap/issues/206

  • Related