2017 © Pedro Peláez
 

library task-daemon

Simple PHP daemon library

image

basarevych/task-daemon

Simple PHP daemon library

  • Sunday, April 19, 2015
  • by ross
  • Repository
  • 2 Watchers
  • 4 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

Task Daemon

Simple PHP fork()ing daemon which runs taks in the background. It uses Gearman internally, but it is not exposed to the user., (*1)

Installation

This daemon requires a running Gearman server and the following PHP extensions:, (*2)

  • pcntl
  • posix
  • openssl
  • gearman

Add to require section of your composer.json:, (*3)

    "basarevych/task-daemon": "0.2.*"

Examples

Have a look at Example directory., (*4)

  • ReverseWordTask.php - our example task
  • InfiniteTask.php - another example (infinitely running)
  • The rest is our example programs
Initialize:
> git clone https://github.com/basarevych/task-daemon
> cd task-daemon
> ./composer.phar install
> cd Example

Start or restart the daemon:
> php 1.start-the-daemon.php

Print 'foobar' in reverse:
> php 2.reverse-word-task.php foobar

Launch our long running task:
> php 3.infinite-task.php

Terminate:
> php 4.stop-the-daemon.php

You can run steps 2 and 3 several times, but if the task is already executing (and is not terminated yet) running it again will do nothing., (*5)

Methods

  • static TaskDaemon::setOptions(), (*6)

    The options:, (*7)

    'namespace' => 'TaskDaemon',                // Set to your project name
    'num_workers' => 10,                        // Number of parallel workers
    'pid_file'  => '/var/run/local-daemon.pid', // PID file path
    'debug' => false,                           // Make the daemon print debug info
    'gearman' => [                              // Gearman options
        'host' => 'localhost',
        'port' => 4730,
    ],
    

    NOTE 'namespace' and 'pid_file' must be the same among all scripts that share the same daemon., (*8)

    NOTE If 'debug' is false (the default) then no text output from the daemon or its tasks will be printed to console., (*9)

  • static TaskDaemon::getInstance(), (*10)

    Get daemon instance (the class is Singleton), (*11)

  • defineTask($name, $object), (*12)

    Define a task. $name should be a unique string and $object must be an instance of a class derived from AbstractTask., (*13)

  • runTask($name, $data = null, $allowDuplicates = false), (*14)

    Run previously defined task. $data will be passed to the task (could be an integer, string or array)., (*15)

    If $allowDuplicates is true, several tasks of the same name and the same data could be run at the same time., (*16)

    For example, while runTask('task1', "data1") is executing call to the same task: runTask("task1", "data1") will be ignored. But task with a different name or data: runTask("task1", "otherdata") or runTask("task2") will be run., (*17)

  • ping(), (*18)

    Return true if we are connected to Gearman server., (*19)

  • getPid(), (*20)

    Returns PID of the daemon or false if the daemon is not running., (*21)

  • start(), (*22)

    Fork() to the background and start executing jobs. Could be called several times as only the first run will fork()., (*23)

  • stop(), (*24)

    Terminate the daemon and its workers, (*25)

  • restart(), (*26)

    Restart the daemon, (*27)

The Versions

19/04 2015

dev-master

9999999-dev https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

19/04 2015

v0.2.6

0.2.6.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

18/04 2015

v0.2.5

0.2.5.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

18/04 2015

v0.2.4

0.2.4.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

18/04 2015

v0.2.3

0.2.3.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

17/04 2015

v0.2.2

0.2.2.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

04/04 2015

v0.2.1

0.2.1.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

03/04 2015

v0.2.0

0.2.0.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

27/03 2015

v0.1.2

0.1.2.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

27/03 2015

v0.1.1

0.1.1.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon

25/03 2015

v0.1.0

0.1.0.0 https://github.com/basarevych/task-daemon

Simple PHP daemon library

  Sources   Download

MIT

The Requires

  • php >=5.4.8
  • ext-pcntl *
  • ext-posix *
  • ext-openssl *
  • ext-gearman *

 

by Ross Basarevych

php daemon