PHP forking and processing MySQL database without conflict -



PHP forking and processing MySQL database without conflict -

i have mysql database table need process. takes 1 sec process 3 rows (due curl connections need create each row). so, need fork php script in order have reasonable time (since process 10,000 rows 1 batch).

i'm going run 10-30 processes @ once, , need way create sure processes not overlapping (in terms of rows retrieving , modifying).

from i've read, there 3 ways accomplish this. i'm trying decide method best situation.

option 1: begin transaction , utilize select ... update , limit # of rows each process. save info array. update selected rows status flag of "processing". commit transaction , update selected rows status of "finished".

option 2: update number of rows status flag of "processing" , process id. select rows process id , flag. work info normal. update rows , set flag "finished".

option 3: set limit ... offset ... clause each process's select query, each process gets unique rows work with. store row ids , perform , update when done.

i'm not sure alternative safest. think alternative 3 seems simple enough, wonder there way fail? alternative 2 seems simple, i'm not sure if locking due update cause slow down. alternative 1 seems best bet, i'm not familiar for update , transactions, , utilize help.

update: clarity, have 1 file process.php selects rows , posts info third-party via curl one-by-one. i'd have fork in file, 10,000 rows can split among 10-30 kid processes.

another way of handling set ids need process redis queue (list). can pop/push items list. when len(list) empty, know there nil left process.

there php resque project implement of job queuing want do.

https://github.com/chrisboulton/php-resque

php mysql parallel-processing fork pcntl

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -