PHP code example of chrisvaughn / faktory_worker_php

1. Go to this page and download the library: Download chrisvaughn/faktory_worker_php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chrisvaughn / faktory_worker_php example snippets


use FaktoryQueue\FaktoryClient;
use FaktoryQueue\FaktoryJob;

$client = new FaktoryClient('localhost', '7419', 'optionalpassword');
$job1 = new FaktoryJob('cooljob', [
    1,
    2
]);

$job2 = new FaktoryJob('cooljob2', [
    3,
    4
]);

$client->push($job1);
$client->push($job2);

$client = new FaktoryClient('faktory', '7419');

$job1 = new FaktoryJob('CoolJob1', [
    1,
    2
]);

$job2 = new FaktoryJob('CoolJob2', [
    3,
    4
]);

$job3 = new FaktoryJob('CoolJob3', [
    5,
    6
]);

$job4 = new FaktoryJob('CoolJob4', [
    7,
    8
]);

$job5 = new FaktoryJob('CoolJob5', [
    9,
    10
]);

$job1->inSeconds(300);
$job2->inMinutes(15);
$job3->inHours(24);

$date = date(DATE_RFC3339, strtotime('+5 days'));
$job4->at($date);    

$client->push($job1);
$client->push($job2);
$client->push($job3);
$client->push($job4);
$client->push($job5);

use FaktoryQueue\FaktoryClient;
use FaktoryQueue\FaktoryWorker;

$client = new FaktoryClient('localhost', '7419', 'optionalpassword');
$worker = new FaktoryWorker($client);

$worker->register('cooljob', function($job) {
    echo "something cool: ".$job['args'][0].' '.$job['args'][1]."\n";
});

$worker->register('cooljob2', function($job) {
    echo "This is cooler: ".$job['args'][0].' '.$job['args'][1]."\n";
});

$worker->run();
shell
composer