forked from easy-swoole/easyswoole
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43eda22
commit 8cd55da
Showing
5 changed files
with
147 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
|
||
namespace EasySwoole\EasySwoole\Process; | ||
|
||
|
||
use EasySwoole\Component\Process\AbstractProcess; | ||
use EasySwoole\Component\Timer; | ||
|
||
class BaseService extends AbstractProcess | ||
{ | ||
protected function run($arg) | ||
{ | ||
/* | ||
* 本进程用于做Easyswoole后续的一些基础附加服务 | ||
*/ | ||
$dir = EASYSWOOLE_TEMP_DIR.'/process.json'; | ||
Timer::getInstance()->loop(1*1000,function ()use($dir){ | ||
$list = Manager::getInstance()->info(); | ||
file_put_contents($dir,json_encode($list,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
|
||
namespace EasySwoole\EasySwoole\Process; | ||
|
||
|
||
use EasySwoole\Component\Process\AbstractProcess; | ||
use EasySwoole\Component\Singleton; | ||
use EasySwoole\Component\TableManager; | ||
use Swoole\Process; | ||
use Swoole\Server; | ||
use Swoole\Table; | ||
|
||
class Manager | ||
{ | ||
use Singleton; | ||
|
||
protected $processList = []; | ||
protected $table; | ||
|
||
function __construct() | ||
{ | ||
TableManager::getInstance()->add(AbstractProcess::PROCESS_TABLE_NAME,[ | ||
'pid'=>[ | ||
'type'=>Table::TYPE_INT, | ||
'size'=>10, | ||
], | ||
'name'=>[ | ||
'type'=>Table::TYPE_STRING, | ||
'size'=>45, | ||
], | ||
'group'=>[ | ||
'type'=>Table::TYPE_STRING, | ||
'size'=>45, | ||
] | ||
]); | ||
$this->table = TableManager::getInstance()->get(AbstractProcess::PROCESS_TABLE_NAME); | ||
} | ||
|
||
|
||
function kill($pidOrGroupName,$sig = SIGTERM) | ||
{ | ||
$list = []; | ||
if(is_numeric($pidOrGroupName)){ | ||
$list[] = $pidOrGroupName; | ||
}else{ | ||
foreach ($this->table as $key => $value){ | ||
if($value['group'] == $pidOrGroupName){ | ||
$list[] = $value['pid']; | ||
} | ||
} | ||
} | ||
|
||
foreach ($list as $pid){ | ||
Process::kill($pid,$sig); | ||
} | ||
} | ||
|
||
function info($pidOrGroupName = null) | ||
{ | ||
$list = []; | ||
if($pidOrGroupName == null){ | ||
foreach ($this->table as $pid =>$value){ | ||
$list[$pid] = $value; | ||
} | ||
}else if(is_numeric($pidOrGroupName)){ | ||
$info = $this->table->get($pidOrGroupName); | ||
if($info){ | ||
$list[$pidOrGroupName] = $info; | ||
} | ||
}else{ | ||
foreach ($this->table as $key => $value){ | ||
if($value['group'] == $pidOrGroupName){ | ||
$list[$key] = $value; | ||
} | ||
} | ||
} | ||
|
||
return $list; | ||
} | ||
|
||
function addProcess(AbstractProcess $process) | ||
{ | ||
$this->processList[] = $process;; | ||
return $this; | ||
} | ||
|
||
function attachToServer(Server $server) | ||
{ | ||
/** @var AbstractProcess $process */ | ||
foreach ($this->processList as $process) | ||
{ | ||
$server->addProcess($process->getProcess()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters