2017 © Pedro Peláez
 

library jorker

Run jobs with multi process.

image

jorker/jorker

Run jobs with multi process.

  • Friday, November 24, 2017
  • by kongxinchi
  • Repository
  • 4 Watchers
  • 8 Stars
  • 420 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 7 % Grown

The README.md

Jorker

Run jobs with multi process. | 脚本多进程执行, (*1)

Features

  • Execute script with multi process. 脚本多进程执行
  • Continue last job that last time stopped. 支持中断续运行
  • Memory overload protection. 内存过载保护
  • Timing report progress. 定时报告进度
  • Highly configurable. 高度可配置

Fixme

  • 已知问题:主进程中有数据库连接时,在子进程退出时会将连接析构,导致主进程中连接失效。

Setup

composer require jorker/jorker

Usage

<?php
  require_once(dirname(__DIR__) . '/vendor/autoload.php');

  $manager = new \Jorker\JobForker(3);
  $manager->allot(function() {

      // RETURN OR YIELD JOBS IN MASTER PROCESS...
      for($i = 0; $i < 100; $i++) {
          yield ['i' => $i];
      }

  })->run(function($job, \Jorker\Slave\Slave $slave) {

      // DO SOMETHING IN SUB PROCESS...
      $slave->logger()->info("use this way if you want print log {$job['i']}.");

  });

Options

\Jorker\JobForker::__construct($limit, $options)

  @param int $limit | Sub process limit. 使用多少个子进程
  @param array $options | configs. 配置项
    [
      "logger" => new SimpleEchoLogger(),     // LoggerInterface. 日志接口
      "logLevel" => LogLevel::INFO,           // Print log which level greater or equal. 打印日志的最低等级
      "slaveMaxMemory" => 256*1024*1024,      // Sub process max memory, if over this value, master will stop this sub process and fork a new one. 子进程最大内存,超出该内存终止子进程,终止后父进程会重新fork一个新的子进程
      "reportInterval" => 600,                // Execute report handler every {reportInterval} seconds. 运行指定秒数后,对运行时统计进行报告
      "reportHandler" => functuin() {echo "REPORT";},  // Execute report handle. 回调函数,运行时统计报告
      "stampFilePath" => "/tmp/stamp.dat",    // File path that save last job when user CTRL+C stopped script. 用于记录上一次中断时,即将执行数据的保存路径
    ]

The Versions

24/11 2017

dev-master

9999999-dev https://github.com/kongxinchi/jorker

Run jobs with multi process.

  Sources   Download

MIT

The Requires

 

The Development Requires

by KL

job script multi process

13/07 2017

v1.1.1

1.1.1.0 https://github.com/kongxinchi/jorker

Run jobs with multi process.

  Sources   Download

MIT

The Requires

 

The Development Requires

by KL

job script multi process

14/05 2017

v1.1

1.1.0.0 https://github.com/kongxinchi/jorker

Run jobs with multi process.

  Sources   Download

MIT

The Requires

 

The Development Requires

by KL

job script multi process

11/05 2017

v1.0

1.0.0.0 https://github.com/kongxinchi/jorker

Run jobs with multi process.

  Sources   Download

MIT

The Requires

 

The Development Requires

by KL

job script multi process