承接 shaggy8871/fork 相关项目开发

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

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

shaggy8871/fork

Composer 安装命令:

composer require shaggy8871/fork

包简介

Fork makes it simple to fork and run multiple child processes from PHP.

README 文档

README

Fork makes it simple to fork and run multiple child processes from PHP.

Build Status

Installation

Make sure PCNTL is installed. This library only works via php-cli.

In composer.json:

"require": {
    "shaggy8871/fork": "dev-master"
}

Then run:

composer install

Callback mode:

<?php

include_once("vendor/autoload.php");

Fork\Fork::createChildren(['test1', 'test2'], function(Fork\ChildProcess $child) {

    // Wait 1 second to allow the broadcast to come through
    sleep(1);

    $child->sendToParent('Hello parent, I got ' . $child->getKey() . ' and "' . $child->receivedFromParent() . '" from you');

    // Wait a random amount of time
    $r = rand(1, 10);
    sleep($r);

    $child->sendToParent('Still here after ' . $r . ' seconds?');

    //... do more work

})->then(function(Fork\ParentProcess $parent) {

    $parent->broadcast('Hello children');

    // Wait for all children to finish running and handle messages
    $parent->waitForChildren(function($message, Fork\Child $child) {
        echo "Got message " . $message . " from child " . $child->getPid() . "\n";
    });

    // Display remaining output from buffer (if any)
    print_r($parent->receivedFromChildren());

    // Ask the parent to clean up after itself
    $parent->cleanup();

});

Normal mode:

<?php

include_once("vendor/autoload.php");

$ps = Fork::createChildren(['test1', 'test2']);

if ($ps->isParent()) {

    $ps->broadcast('Hello children');

    // Wait a second to ensure children have had a chance to fork
    sleep(1);

    // Display output from buffer
    print_r($ps->receivedFromChildren());

    // Wait for all children to finish running...
    $ps->waitForChildren();

    // Display remaining output from buffer (if any)
    print_r($ps->receivedFromChildren());

    // Ask the parent to clean up after itself
    $ps->cleanup();

    exit(0);

} else {

    $ps->sendToParent('Hello parent, I got ' . $ps->getKey() . ' and "' . $ps->receivedFromParent() . '" from you');

    sleep(5);

    $ps->sendToParent('Still here?');

    //... do work

    // Child must shut itself down properly
    $ps->shutdown();

}

Contact

License

Fork may be freely distributed under the MIT license.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固