PHP + MySQL Queue

I need a simple table that acts as a queue. My limitation of the MySQL server is that I cannot use InnoDB tables, only MyISAM.

Clients / workers will work at the same time, and each time they will receive different tasks.

My idea is to do the following (pseudocode):

$job <- SELECT * FROM queue ORDER BY last_pop ASC LIMIT 1;
UPDATE queue SET last_pop WHERE id = $job->id
return $job

I tried locking tables and "GET_LOCK", but nothing happens, workers sometimes get the same jobs.

+5
source share
3 answers

You need to rotate your order so that there is no time window.

Consumer POP (each consumer has a unique $ consumer_id)

Update queue 
set last_pop = '$consumer_id' 
where last_pop is null 
order by id limit 1;

$job = 
  Select * from queue 
  where last_pop = '$consumer_id' 
  order by id desc 
  limit 1;

PUSH Provider

insert into queue 
  (id, last_pop, ...) 
values 
  (NULL, NULL, ...);

id POP user_id.

+13

, Gearman , : Rasmus Lerdorf .

+1

. $consumer_id . , cron , pid consumer ID.

UPDATE , ID.

, last_pop consumer_id, , X, .

0
source

All Articles