Queue management in PHP. Purpose of this library is to have basic queue management for common hosting. Cron job, that opens webpage in some interval is what will be enough. Is it possible to set max time limit for running jobs as many hosting services has limited execution time. Main goal was to run tasks in background that needs to run slow.
Useful when you do not have possibility to instal any queue management
Add to project using composer
composer require queues/queue-manager:1.0.0@devCreate custom job. Just extend \Queue\Job and override run method. Run method returns transformed data.
class LongJob extends \Queue\Job {
public function run() {
sleep(10);
return $this->getData();
}
}When creating instance of QueeuManager, pass context and queue name. Context can be empty or array or some manager.
$queue='MyQueue';
$context=array();
$newJob = new LongJob()
$queuemanager = new QueueManager($context, $queue);
$queuemanager->getQueue($name)->addJob($newJob);If you using some kind of framework, e.g. Symfony, you can use dependency injection to get instance of QueueManager.
$queuemanager->getRunner($name)->runJobs();$queuemanager->getRunner($name)->loop();$maxJobCount - how many jobs will run in one loop $maxJobTime - how long can run one loop cycle. This is useful if you running loop by calling weburl with cron job and page execution has execution time limit. $sleeptime - sleep time when run in loop
$runner = $queuemanager->getRunner($name);
$runner->maxJobCount=1;class MyAppJob extends \Queue\Job {
public $connection;
public function init($context=NULL) {
$this->connecton=$context->get(\My\Connection::class);
}
}Queue interface provides methosds to get list of queued Jobs