2017 © Pedro Peláez
 

library worker

Worker thread used to run your callback in another process

image

arkanmgerges/worker

Worker thread used to run your callback in another process

  • Wednesday, April 27, 2016
  • by arkanmgerges
  • Repository
  • 1 Watchers
  • 6 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Description

Worker is a simple library that will allow the user to provide a function or class method to be executed into a separate php process, beside this, it accepts on success function or class method, and on error function or class method., (*1)

License

Licensed under MIT. Totally free for private or commercial projects., (*2)

Requirement

The library needs PHP 5.4+., (*3)

Installation

In your composer.json add the following in the require section:, (*4)

{
    "require": {
        "arkanmgerges/worker": "dev-master"
    }
}

And then:, (*5)

php composer.phar update

or if you have installed composer in your system to be called directly without php then:, (*6)

composer update

Tutorial

1. Use Worker

Use Worker\Worker

2. Using Anonymous Function

$worker = new Worker(
    // Here you can provide your main callback
    function($arg1 = '', $arg2 = '') {
        file_put_contents('result.txt', $arg1 . $arg2);
    },
    // The second one is used when main callback has completed successfully
    function() {
        file_put_contents('success.txt', 'success');
    },
    // If an exception has happened in the main callback then this callback will be called with an error message
    function($e) {
        file_put_contents('error.txt', 'error');
    }
);

// Start the worker, and pass 2 arguments to the main callback. It is also possible to pass more arguments
$worker->start('first arg', 'second arg');

3. Using Class Object Method

class SomeClass
{
    public function method($arg1, $arg2, $arg3)
    {
        file_put_contents('result.txt', $arg1 . $arg2 . $arg3);
    }
};

And then somewhere:, (*7)

$object = new SomeClass();
// Pass array, first item is the object and second item is the name of the class method
$worker = new Worker([$object, 'method']);
// Start worker and send 3 arguments
$worker->start('from', ' object method', ', this is nice');

4. Using Class Static Method

class SomeClass
{
    public static function method($arg1, $arg2, $arg3)
    {
        file_put_contents('result.txt', $arg1 . $arg2 . $arg3);
    }
};

And somewhere:, (*8)

$worker = new Worker(__NAMESPACE__ . '\SomeClass::method');
$worker->start('from', ' class method', ', nice');

The Versions

27/04 2016

dev-master

9999999-dev https://github.com/arkanmgerges/worker

Worker thread used to run your callback in another process

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

worker process parallel callback

07/07 2014

0.1.0

0.1.0.0 https://github.com/arkanmgerges/worker

Worker thread used to run your callback in another process

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

worker process parallel callback