-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProc2.php
77 lines (64 loc) · 2.24 KB
/
Proc2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace App\Console;
use Soli\Console\Command;
use Soli\Process;
/**
* 终端命令结合多进程
*/
class Proc2 extends Command
{
/** @var bool $runnable 这个属性决定了action是否以多进程方式运行 */
protected $runnable = false;
/** @var string $name 进程名称,只在 Linux 系统下起作用 */
protected $name = 'soli console proc2';
/** @var int $count 进程数 */
protected $count = 4;
/** @var bool $daemonize 是否以守护进程方式运行 */
protected $daemonize = false;
/** @var bool $refork 是否自动补充退出的进程 */
protected $refork = false;
/** @var string $logFile 记录进程的输出、终止等信息到此文件 */
protected $logFile = '/tmp/soli-console-proc2.log';
public function __construct()
{
// 针对不同的 action 可以选择是否使用多进程,以及指定不同的进程属性
$action = $this->dispatcher->getActionName();
switch ($action) {
case 'command':
$this->runnable = false;
break;
case 'process':
$this->runnable = true;
$this->logFile = null;
break;
case 'daemonize':
$this->runnable = true;
$this->daemonize = true;
echo "Process output info in {$this->logFile}\n";
break;
case 'refork':
$this->runnable = true;
$this->refork = true;
break;
}
}
public function command($name = 'wukong')
{
echo "hello $name. just a command.\n";
}
/**
* $worker 参数将成为 action 的第一个参数,$worker 参数之后是从命令行输入的参数
*/
public function process(Process $worker, $name = 'wukong')
{
echo "hello $name. dump message from [worker:{$worker->id} {$worker->workerPid}] process.\n";
}
public function daemonize(Process $worker)
{
echo "dump message from [worker:{$worker->id} {$worker->workerPid}] daemonize process.\n";
}
public function refork(Process $worker)
{
echo "dump message from [worker:{$worker->id} {$worker->workerPid}] process.\n";
}
}