Skip to content

Commit

Permalink
change class name and add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
xinchi.kong committed May 14, 2017
1 parent 717eadc commit 0bf6885
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 23 deletions.
4 changes: 2 additions & 2 deletions example/custom_logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public function log($level, $message, array $context = array())
}
}

$manager = new \Jorker\JobForkerManager(3, [
$forker = new \Jorker\JobForker(3, [
"logger" => new CustomLogger(),
'logLevel' => \Psr\Log\LogLevel::DEBUG
]);
$manager->allot(function() {
$forker->allot(function() {
for($i = 0; $i < 100; $i++) {
yield ['i' => $i];
}
Expand Down
4 changes: 2 additions & 2 deletions example/custom_report.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
require_once(dirname(__DIR__) . '/vendor/autoload.php');

$manager = new \Jorker\JobForkerManager(3, [
$forker = new \Jorker\JobForker(3, [
"reportInterval" => 1, // 运行指定秒数后,对运行时统计进行报告
"reportHandler" => function(\Jorker\MasterStatistics $statistics) {
$fp = fopen('report.txt', 'a');
fwrite($fp, date('Y-m-d H:i:s') . "|" . $statistics->formattedInfo() . PHP_EOL);
fclose($fp);
}
]);
$manager->allot(function() {
$forker->allot(function() {
$result = [];
for($i = 0; $i < 100; $i++) {
$result[] = ['i' => $i];
Expand Down
4 changes: 2 additions & 2 deletions example/failhandler.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
require_once(dirname(__DIR__) . '/vendor/autoload.php');

$manager = new \Jorker\JobForkerManager(3);
$manager->allot(function() {
$forker = new \Jorker\JobForker(3);
$forker->allot(function() {
for($i = 0; $i < 5; $i++) {
yield ['i' => $i];
}
Expand Down
4 changes: 2 additions & 2 deletions example/options.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
require_once(dirname(__DIR__) . '/vendor/autoload.php');

$manager = new \Jorker\JobForkerManager(3, [
$forker = new \Jorker\JobForker(3, [
"logger" => new \Jorker\Logger\SimpleEchoLogger(), // 日志接口
"logLevel" => \Psr\Log\LogLevel::DEBUG, // 打印日志的最低等级
"slaveMaxMemory" => 256*1024*1024, // 子进程最大内存,超出该内存终止子进程,终止后父进程会重新fork一个新的子进程
"reportInterval" => 1, // 运行指定秒数后,对运行时统计进行报告
"stampFilePath" => "/tmp/stamp.dat" // 用于记录上一次中断时即将执行的数据
]);
$manager->allot(function() {
$forker->allot(function() {
for($i = 1; $i < 100; $i++) {
yield ['i' => $i];
}
Expand Down
4 changes: 2 additions & 2 deletions example/simple.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
require_once(dirname(__DIR__) . '/vendor/autoload.php');

$manager = new \Jorker\JobForkerManager(3);
$manager->allot(function() {
$forker = new \Jorker\JobForker(3);
$forker->allot(function() {
$jobs = [];
for($i = 0; $i < 100; $i++) {
$jobs[] = ['i' => $i];
Expand Down
4 changes: 2 additions & 2 deletions example/stopandcontinue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* next time you run this script, the arg $start will be the first not execute job
*/

$manager = new \Jorker\JobForkerManager(1);
$manager->allot(function($start) {
$forker = new \Jorker\JobForker(1);
$forker->allot(function($start) {
$i = is_null($start) ? 0 : $start['i'];
for(; $i < 100; $i++) {
usleep(100000);
Expand Down
4 changes: 2 additions & 2 deletions example/yield.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
require_once(dirname(__DIR__) . '/vendor/autoload.php');

$manager = new \Jorker\JobForkerManager(3);
$manager->allot(function() {
$forker = new \Jorker\JobForker(3);
$forker->allot(function() {
for($i = 0; $i < 100; $i++) {
yield ['i' => $i];
}
Expand Down
6 changes: 3 additions & 3 deletions src/JobForkerManager.php → src/JobForker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

/**
* 多进程任务执行
* Class JobForkerManager
* @package Gaia\Helpers\JobForker
* Class class JobForker
* @package Jorker
*/
class JobForkerManager
class JobForker
{
/**
* 日志接口
Expand Down
5 changes: 5 additions & 0 deletions src/Logger/LoggerWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

/**
* 日志接口包装,使调用者可以限制输出的日志等级
* Class LoggerWrapper
* @package Jorker\Logger
*/
class LoggerWrapper implements LoggerInterface
{

Expand Down
4 changes: 2 additions & 2 deletions src/Logger/SimpleEchoLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use Psr\Log\AbstractLogger;

/**
* 将日志输出到屏幕
* 默认的日志接口实现,将日志简单的输出到屏幕
* Class SimpleEchoLogger
* @package Gaia\Helpers\JobForker
* @package Jorker\Logger
*/
class SimpleEchoLogger extends AbstractLogger
{
Expand Down
5 changes: 5 additions & 0 deletions src/MasterStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

use Jorker\Slave\SlaveResponse;

/**
* 父进程中统计脚本执行情况
* Class MasterStatistics
* @package Jorker
*/
class MasterStatistics
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Slave/Error/SlaveError.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
namespace Jorker\Slave\Error;

/**
* 子进程响应回传时,对于造成进程崩溃的错误的封装
* Class SlaveError
* @package Jorker\Slave\Error
*/
class SlaveError implements SlaveErrorInterface
{
/**
Expand Down
6 changes: 5 additions & 1 deletion src/Slave/Error/SlaveErrorInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
namespace Jorker\Slave\Error;


/**
* 子进程错误封装接口
* Interface SlaveErrorInterface
* @package Jorker\Slave\Error
*/
interface SlaveErrorInterface
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Slave/Error/SlaveException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
namespace Jorker\Slave\Error;

/**
* 子进程响应回传时,对于执行异常的封装
* Class SlaveException
* @package Jorker\Slave\Error
*/
class SlaveException implements SlaveErrorInterface
{
protected $className;
Expand Down
5 changes: 5 additions & 0 deletions src/Slave/Slave.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
use Jorker\SocketCommunicate;
use Psr\Log\LoggerInterface;

/**
* 子进程类,任务轮训
* Class Slave
* @package Jorker\Slave
*/
class Slave
{
/**
Expand Down
6 changes: 5 additions & 1 deletion src/Slave/SlaveInfo.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
namespace Jorker\Slave;


/**
* 子进程运行状态
* Class SlaveInfo
* @package Jorker\Slave
*/
class SlaveInfo
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Slave/SlaveKeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* 主进程对子进程状态的维护,对象在主进程中
* Class SlaveKeeper
* @package Gaia\Helpers\JobForker
* @package Jorker\Slave
*/
class SlaveKeeper
{
Expand Down
5 changes: 5 additions & 0 deletions src/Slave/SlaveRequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
namespace Jorker\Slave;

/**
* 父进程任务分发请求
* Class SlaveRequest
* @package Jorker\Slave
*/
class SlaveRequest
{
const TYPE_RUN = 'run';
Expand Down
5 changes: 5 additions & 0 deletions src/Slave/SlaveResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Jorker\Slave\Error\SlaveErrorInterface;
use Jorker\Slave\Error\SlaveException;

/**
* 子进程响应回传
* Class SlaveResponse
* @package Jorker\Slave
*/
class SlaveResponse
{
/**
Expand Down
6 changes: 5 additions & 1 deletion src/SocketCommunicate.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

namespace Jorker;

/**
* 主进程与进程通信
* Class SocketCommunicate
* @package Jorker
*/
class SocketCommunicate
{
public static function send($handler, $data)
Expand Down

0 comments on commit 0bf6885

Please sign in to comment.