# worker **Repository Path**: dz/worker ## Basic Information - **Project Name**: worker - **Description**: No description available - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-04-19 - **Last Updated**: 2022-04-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 单文件多进程处理框架 复制于[workerman](https://github.com/walkor/workerman) ## Installation ``` composer require myphps/worker ``` ## Usage ```php name = 'test'; $worker->count = 2; //进程数 $worker->alarm = 100; //失败预警值 $worker->onWorkerStart = function (\Worker\Worker $worker) { //todo 引用代码 //增加定时器 \Worker\Timer::add(1, function () use ($worker) { echo 'okT--------------------------------------------------' . $worker->id . ':' . time() . PHP_EOL; }); }; $worker->onRun = function (\Worker\Worker $worker) { $rand = mt_rand(0, 9); //模拟处理结果 if ($rand == 0) { echo 'fail--------' . $worker->id . ':' . time() . PHP_EOL; $result = false; //失败 } elseif ($rand <= 5) { echo 'ok----------' . $worker->id . ':' . time() . PHP_EOL; $result = true; //成功 } else { $result = null; //没有任何处理 } return $result; //运行结果 }; $worker->onAlarm = function (\Worker\Worker $worker) { echo date("Y-m-d H:i:s") . '................. alarm ................. ' . PHP_EOL; }; $worker->onWorkerStop = function (\Worker\Worker $worker) { echo 'end', PHP_EOL; }; // Run worker \Worker\Worker::runAll(); ```