mysql - PHP Web Service Queue -


i connecting web service allows max (could 1,5,10 depending on license) concurrent connections same source. need solution can in real time (not asynchronously) queue requests web service, ensuring max request running @ once.

i have current set working:

$jobid = $this->queue->addjob($operation);                while ( !$this->queue->canrunjob($jobid) ) {   //error_log("queue full, waiting");                         usleep(500);                                     } $this->queue->runjob($jobid); ... $this->queue->completejob($jobid); 

this uses custom queue class, uses mysql table track jobs, , count number of actively running , pending jobs.

$this->queue->addjob adds new job database, status of "pending"

$this->queue->canrunjob($jobid) checks see how many running jobs there are. if there less max jobs running, grab next pending job list in fifo order.

the php script looping , sleeping until job can run.

once canrunjob calls $this->queue->runjob($jobid) updates job in queue "running" , sends request webservice.

when webservice returns response calls $this->queue->completejob($jobid) updates job in queue "completed".

this works 95% of time, if web service provider bogged down, or down completely, causes process buildup on server locks web , database connections.

looking suggestions of way handle scenario without looping / sleeping

throw glance @ process component of symfony 2. able trigger subprocesses can work, e.g. api connection. parent can make sure n subprocesses fired. pack in loop , query each job status in there.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -