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
Post a Comment