Giter Club home page Giter Club logo

faktory_worker's Introduction

Faktory PHP 5 Library

Faktory job queue library for PHP. Compatible with PHP 5.6 (and maybe lower, but untested)

Supported Faktory versions

  • 0.9.7
  • 1.0.1

It could work on earlier versions, but untested.

Installation / Usage

Formal instructions are coming soon. In the meantime, use Composer to install the package:

composer require jcs224/faktory_worker_php5

Pushing jobs

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);

Scheduled jobs

You can also schedule when jobs will run as you push them onto the queue. Here are some examples:

$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);

Starting a worker that listens for jobs

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(true);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.