我想创建一个php服务器。 我发出命令以异步方式启动服务器。 我想下订单来停止服务器。 运行启动命令后,我无法获取进程。
运行命令
$server = new Server();
$pid = pcntl_fork();
if ($pid > 0) {
echo "Server Runned";
return;
}
$server->Run();
服务器类
class Server {
private $_loop;
private $_socket;
public function __construct() {
$this->_loop = Factory::create();
$this->_socket = new ReactServer($this->_loop );
$this->_socket->on(
'connection',function ($conn) {
echo "Connection";
}
);
}
public static function Stop () {
$this->_loop-> stop();
}
public function Run () {
$this->_loop->run();
}
}
感谢您的帮助!
答案 0 :(得分:0)
我已经解决了我的问题。
当我启动服务器时,我在系统的tmp目录中创建一个文件。 在我的循环中,我检查此文件是否已存在。如果删除了,我就会停止循环。
因此,要停止我的服务器,我可以删除该文件。
要打开不同的服务器,我用主机和端口命名(例如:〜/ 127-0-0-1-8080.pid)。
$server = new Server($em, $port, $host);
$pid = pcntl_fork();
if ($pid > 0) {
$address = $host.":".$port;
echo "Server Starting " . $adresse;
}
$server->Run();
启动命令:
$host = '127.0.0.1';
$port = 5821;
$lockFile = Loop::getLockFile($host.":".$port);
unlink($lockFile);
echo "Server Stopped";
停止命令:
<div class="divTable svc-adv" id="info">
<div class="divTableBody adv-body">
<div class="divTableRow adv-row">
<div class="divTableCell adv-cell snmhdr">Title</div>
<div class="divTableCell adv-cell stitlehdr">Service Name</div>
<div class="divTableCell adv-cell snhdr">Service Number</div>
</div>
</div>
</div>
<div class="divTable svc-adv servicealert">
<div class="divTableBody adv-body">
<div class="divTableRow adv-row">
<div class="divTableCell adv-cell advtitle">WAS</div>
<div class="divTableCell adv-cell advsnm">ABC</div>
<div class="divTableCell adv-cell advsnum">123</div>
</div>
</div>
</div>
<div class="divTable svc-adv servicealert">
<div class="divTableBody adv-body">
<div class="divTableRow adv-row">
<div class="divTableCell adv-cell advtitle">NYP</div>
<div class="divTableCell adv-cell advsnm">XYZ</div>
<div class="divTableCell adv-cell advsnum">321</div>
</div>
</div>
</div>