diff --git a/example/custom_logger.php b/example/custom_logger.php index f31bf83..2c4b46e 100644 --- a/example/custom_logger.php +++ b/example/custom_logger.php @@ -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]; } diff --git a/example/custom_report.php b/example/custom_report.php index e961b19..4bffa2a 100644 --- a/example/custom_report.php +++ b/example/custom_report.php @@ -1,7 +1,7 @@ 1, // 运行指定秒数后,对运行时统计进行报告 "reportHandler" => function(\Jorker\MasterStatistics $statistics) { $fp = fopen('report.txt', 'a'); @@ -9,7 +9,7 @@ fclose($fp); } ]); -$manager->allot(function() { +$forker->allot(function() { $result = []; for($i = 0; $i < 100; $i++) { $result[] = ['i' => $i]; diff --git a/example/failhandler.php b/example/failhandler.php index f590221..71e6cb5 100644 --- a/example/failhandler.php +++ b/example/failhandler.php @@ -1,8 +1,8 @@ allot(function() { +$forker = new \Jorker\JobForker(3); +$forker->allot(function() { for($i = 0; $i < 5; $i++) { yield ['i' => $i]; } diff --git a/example/options.php b/example/options.php index 97f6a2d..74929f5 100644 --- a/example/options.php +++ b/example/options.php @@ -1,14 +1,14 @@ 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]; } diff --git a/example/simple.php b/example/simple.php index 58049dd..7c81731 100644 --- a/example/simple.php +++ b/example/simple.php @@ -1,8 +1,8 @@ allot(function() { +$forker = new \Jorker\JobForker(3); +$forker->allot(function() { $jobs = []; for($i = 0; $i < 100; $i++) { $jobs[] = ['i' => $i]; diff --git a/example/stopandcontinue.php b/example/stopandcontinue.php index 3a1a7a8..88b9615 100644 --- a/example/stopandcontinue.php +++ b/example/stopandcontinue.php @@ -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); diff --git a/example/yield.php b/example/yield.php index eecc843..368a2ee 100644 --- a/example/yield.php +++ b/example/yield.php @@ -1,8 +1,8 @@ allot(function() { +$forker = new \Jorker\JobForker(3); +$forker->allot(function() { for($i = 0; $i < 100; $i++) { yield ['i' => $i]; } diff --git a/src/JobForkerManager.php b/src/JobForker.php similarity index 98% rename from src/JobForkerManager.php rename to src/JobForker.php index 0e0300a..20d99ff 100644 --- a/src/JobForkerManager.php +++ b/src/JobForker.php @@ -9,10 +9,10 @@ /** * 多进程任务执行 - * Class JobForkerManager - * @package Gaia\Helpers\JobForker + * Class class JobForker + * @package Jorker */ -class JobForkerManager +class JobForker { /** * 日志接口 diff --git a/src/Logger/LoggerWrapper.php b/src/Logger/LoggerWrapper.php index 0de066c..ebdb322 100644 --- a/src/Logger/LoggerWrapper.php +++ b/src/Logger/LoggerWrapper.php @@ -4,6 +4,11 @@ use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; +/** + * 日志接口包装,使调用者可以限制输出的日志等级 + * Class LoggerWrapper + * @package Jorker\Logger + */ class LoggerWrapper implements LoggerInterface { diff --git a/src/Logger/SimpleEchoLogger.php b/src/Logger/SimpleEchoLogger.php index b22f362..7116331 100644 --- a/src/Logger/SimpleEchoLogger.php +++ b/src/Logger/SimpleEchoLogger.php @@ -4,9 +4,9 @@ use Psr\Log\AbstractLogger; /** - * 将日志输出到屏幕 + * 默认的日志接口实现,将日志简单的输出到屏幕 * Class SimpleEchoLogger - * @package Gaia\Helpers\JobForker + * @package Jorker\Logger */ class SimpleEchoLogger extends AbstractLogger { diff --git a/src/MasterStatistics.php b/src/MasterStatistics.php index a4b9b12..3c527f4 100644 --- a/src/MasterStatistics.php +++ b/src/MasterStatistics.php @@ -3,6 +3,11 @@ use Jorker\Slave\SlaveResponse; +/** + * 父进程中统计脚本执行情况 + * Class MasterStatistics + * @package Jorker + */ class MasterStatistics { /** diff --git a/src/Slave/Error/SlaveError.php b/src/Slave/Error/SlaveError.php index 61353ed..76e643a 100644 --- a/src/Slave/Error/SlaveError.php +++ b/src/Slave/Error/SlaveError.php @@ -1,6 +1,11 @@