PHP Classes

Optimisations

Recommend this page to a friend!

      PHP Classes blog  >  How to Use Queue To S...  >  All threads  >  Optimisations  >  (Un) Subscribe thread alerts  
Subject:Optimisations
Summary:One or more workers
Messages:2
Author:Lionel F. Lebeau
Date:2016-03-09 13:46:43
Update:2016-03-10 19:11:01
 

  1. Optimisations   Reply   Report abuse  
Picture of Lionel F. Lebeau Lionel F. Lebeau - 2016-03-09 18:55:23
Using one Worker at a time :
If you run only one Worker and it has to process a bunch of records, you may run into a race to access the same record when a new Worker is launched and the precedent one has not finished its job.
You can check if a pid file exists at construct phase and, if not, create it.
It will be deleted at the end of the process.

As the items are processed in order, you can optimize the database access by dropping the markItemAsBeingProcessed($item) function.

You can also launch more than one Worker at a time. There are different ways to do it (exec, pnctl_fork, curl_multi_exec, gearman, fsockopen...).


  2. Re: Optimisations   Reply   Report abuse  
Picture of Alexander Skakunov Alexander Skakunov - 2016-03-10 19:11:01 - In reply to message 1 from Lionel F. Lebeau
Yes, the jobs need to be marked when they are given to a particular worker.
If you go with database solution like I did, you can use SELECT...FOR UPDATE query just for that.
Other solutions support this too of course.