2017 © Pedro PelĆ”ez
 

library isolated-callback

Allows to execute a callback in a separate fork

image

vatson/isolated-callback

Allows to execute a callback in a separate fork

  • Friday, December 5, 2014
  • by vatson
  • Repository
  • 1 Watchers
  • 4 Stars
  • 2,414 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Isolated Callback Build Status Latest Stable Version Total Downloads License

Tiny but still powerful tool to fork it all., (*1)

Isolated callback allows to execute any callable statement in a fork and avoid memory leaks., (*2)

Installation

Installation is damn easy, thanks to Composer:, (*3)

composer require vatson/isolated-callback

or add the requirements to your composer.json file, (*4)

{
    "require": {
        "vatson/isolated-callback": "*"
    }
}

and run update, (*5)

composer update vatson/isolated-callback

Usage

Quick and easy. Let's create some anonymous function that generates a lot of data, but the result is a small, (*6)

<?php
include_once 'vendor/autoload.php';

use Vatson\Callback\IsolatedCallback;

$cb = function() {
    return array_slice(range(1, 100000), rand(1,100), rand(1,10));
};

$icb = new IsolatedCallback($cb);
$random_slice = $icb();

That's it. Your callback will be run in separate fork and the result will be sent to the main process., (*7)

Callback arguments

Note, you can call it with args and bind some local vars with your lambda functions., (*8)

<?php
include_once 'vendor/autoload.php';

use Vatson\Callback\IsolatedCallback;

$slice_length = rand(1,5);
$cb = function($max_range) use($slice_length) {
    return array_slice(range(1, $max_range), rand(1,$max_range), $slice_length);
};

$icb = new IsolatedCallback($cb);
$random_slice = $icb(1000);

Objects as a result

Also you can send not only scalars, but simple objects (POPO). And rember, objects based on or which contain Resources can't be serialized as a result., (*9)

<?php

use Vatson\Callback\IsolatedCallback;

$cb = function() {
    $popo_object = new \stdClass();
    $popo_object->property = 'value';
    return $popo_object;
};

$icb = new IsolatedCallback($cb);
$property = $icb()->property;

Restrictions

Beware, the current implementation uses System V IPC to share a result between processes. Amount of transferred data depends on your system configuration. The best practice is to send short but succinct results., (*10)

Requirements

  • PHP >= 5.3.2, (*11)

  • Process Control (PCNTL) - allows to make a fork, (*12)

  • System V IPC (semaphore) - adds an ability to share the results between distributed processes, (*13)

  • [Optional] Fumocker - mocks the php's built-in functions, (*14)

  • [Optional] PHPUnit 3.5+ to execute the test suite, (*15)

Authors

License

Isolated Callback is distributed under the terms of the MIT license - see theĀ LICENSEĀ file for details, (*18)

The Versions

05/12 2014

dev-master

9999999-dev https://github.com/vatson/isolated-callback

Allows to execute a callback in a separate fork

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-pcntl *
  • ext-sysvsem *

 

The Development Requires

by Vadim Tyukov
by Slava Hatnuke

daemon callback fork closure leakage

03/12 2013

1.0.1

1.0.1.0 https://github.com/vatson/isolated-callback

Allows to execute a callback in a separate fork

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-pcntl *
  • ext-sysvsem *

 

The Development Requires

by Vadim Tyukov
by Slava Hatnuke

daemon callback fork closure leakage

03/12 2013

1.0.0

1.0.0.0 https://github.com/vatson/isolated-callback

Allows to execute a callback in a separate fork

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-pcntl *
  • ext-sysvsem *

 

The Development Requires

by Vadim Tyukov
by Slava Hatnuke

daemon callback fork closure leakage