承接 vatson/isolated-callback 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vatson/isolated-callback

Composer 安装命令:

composer require vatson/isolated-callback

包简介

Allows to execute a callback in a separate fork

README 文档

README

Tiny but still powerful tool to fork it all.

Isolated callback allows to execute any callable statement in a fork and avoid memory leaks.

Installation

Installation is damn easy, thanks to Composer:

composer require vatson/isolated-callback

or add the requirements to your composer.json file

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

and run update

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

<?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.

Callback arguments

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

<?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.

<?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.

Requirements

  • PHP >= 5.3.2

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

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

  • [Optional] Fumocker - mocks the php's built-in functions

  • [Optional] PHPUnit 3.5+ to execute the test suite

Authors

License

Isolated Callback is distributed under the terms of the MIT license - see the LICENSE file for details

统计信息

  • 总下载量: 2.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-09-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固