承接 tasoft/process 相关项目开发

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

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

tasoft/process

Composer 安装命令:

composer require tasoft/process

包简介

README 文档

README

This library controls process management using the PHP extension pcntl.

Installation

$ composer require tasoft/process
Simple Usage
<?php
use TASoft\Util\Process;

$process = new Process(function() {
    // Do stuff
});

// Now it will fork the process and call the callback function in separate process.
$process->run();

// Do other stuff in main process

// Wait until the child process has done
$process->wait();
// or kill the child process immediately.
$process->kill();
Problem

The main problem is that a forked process runs in an exact copy of the environment.
That means, on calling $process->run() the child process gets a copy of the current environment.

This raises two problems:

  1. Everything you change (properties, $variables, etc) in the child process, remains there.
  2. Everything you change in the parent process, remains there also.
Solution

I use the Pipe class. It creates a unix socket pair to communicate between the two processes.

Example With Pipe
<?php
use TASoft\Util\Process;

$process = new Process(function(Process $childProcess) {
    $result = NULL;
    
    // Do hard stuff
    
    // Please don't import the parent process!
    $childProcess->sendData( $result );
});

$process->run();

// Do other stuff

$data = $process->receiveData();
echo $data;

$process->wait(); // or kill

Don't import the parent process!

<?php
use TASoft\Util\Process;

$process = new Process(function() use (&$process) {
    $result = NULL;
    // Do stuff
    $process->sendData( $result );
    
    // This is wrong and will not work because $process IS A COPY OF THE MAIN PROCESS!
});

...

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固