PHP Classes

File: src/worker.php

Recommend this page to a friend!
  Classes of Chun-Sheng, Li   Scheduler   src/worker.php   Download  
File: src/worker.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Scheduler
Queue jobs to be executed by worker tasks
Author: By
Last change:
Date: 2 months ago
Size: 815 bytes
 

Contents

Class file image Download
<?php
   
namespace peter\Scheduler;
    require_once
__DIR__.'/../vendor/autoload.php';
    require_once
__DIR__.'/Loader.php';
    require_once
__DIR__.'/MonitorJob.php';
    require_once
__DIR__.'/WeatherJob.php';

    use
Illuminate\Queue\Worker;

   
$queue = Loader::loadDriver();

   
$worker = new Worker($queue->getQueueManager(), null, null);

   
$theTime = time();
    echo
'The Queue Worker ha been started...'.PHP_EOL.PHP_EOL;
   
// Run indefinitely
   
while (true) {
       
// Parameters:
        // 'default' - connection name
        // 'default' - queue name
        // delay
        // time before retries
        // max number of tries
       
$worker->pop('default', 'default', 0, 3, 1);
       
$timeout = time() - $theTime;
        if (
$timeout > 120) {
            break;
        }
    }