sowe/parallel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sowe/parallel

Composer 安装命令:

composer require sowe/parallel

包简介

PHP ext-parallel pool-worker abstraction

README 文档

README

PHP ext-parallel pool-worker abstraction

Requirements

  • PHP ^7.2
  • Parallel (ext-parallel) ^1

Install

composer require sowe/parallel

If your composer doesn't run your zts-php you can also install it running:

zts-php /usr/bin/composer require sowe/parallel

Example

<?php

use Sowe\Parallel\Pool;

$bootstrap = dirname(__DIR__) . "/vendor/autoload.php";
include $bootstrap;

$load = function($id){
    // This will make $logger variable to be created thread-context global.
    global $logger;
    $logger = function($id, $msg){
        echo "Thread " . $id . " says: " . $msg . PHP_EOL;
    };
};

$task = function($id, $msg){
    // Getting our global $logger for this task.
    global $logger;
    $logger($id, $msg);
};

// Creating a poll of 3 Workers.
$worker = new Pool(3, $bootstrap);
$worker->runAll($load);
$worker->run($task, "This is the 1st task");
$worker->run($task, "This is the 2nd task");
$worker->run($task, "This is the 3rd task");
$worker->run($task, "This is the 4th task");
$worker->run($task, "This is the 5th task");
$worker->run($task, "This is the 6th task");
$worker->run($task, "This is the 7th task");
$worker->run($task, "This is the 8th task");
$worker->run($task, "This is the 9th task");
$worker->stop();

Result:

Thread 52b95298ad5eaa92e23a7ff00f3dda45 says: This is the 1st task
Thread 920be484d88bab0b3cef633ec4beafe6 says: This is the 2nd task
Thread 735bd40cc4c50243ff17fae2ab730da2 says: This is the 3rd task
Thread 52b95298ad5eaa92e23a7ff00f3dda45 says: This is the 4th task
Thread 920be484d88bab0b3cef633ec4beafe6 says: This is the 5th task
Thread 735bd40cc4c50243ff17fae2ab730da2 says: This is the 6th task
Thread 52b95298ad5eaa92e23a7ff00f3dda45 says: This is the 7th task
Thread 920be484d88bab0b3cef633ec4beafe6 says: This is the 8th task
Thread 735bd40cc4c50243ff17fae2ab730da2 says: This is the 9th task

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固