php - Access to a server process after start command -


i want create php server. made command start server asynchronously. place order stop server. can not process after running start command.

run command

$server = new server(); $pid = pcntl_fork(); if ($pid > 0) {     echo "server runned";     return; } $server->run(); 

server class

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();     } } 

thanks !

i have solved problems.

when launch server, create file in tmp directory of system. in loop, tcheck if file present. if removed, stop loop.

so, stop server, can remove file.

to can open different server, name host , ports (for exemple : ~/127-0-0-1-8080.pid).

class loop {     private $lockfile;      public static function getlockfile($address)     {         return sys_get_temp_dir().'/'.strtr($address, '.:', '--').'.pid';     }      public function __construct($address)     {         $this->lockfile = loop::getlockfile($address);         touch($this->lockfile);         //...     }     public function run()     {         $this->running = true;         while ($this->running) {              if (!file_exists($this->lockfile)) {                 $this->running = false;                 echo "file removed";             }             //...         }     }     public function stop()     {         $this->running = false;         unlink($this->lockfile);     }  } 

start command :

$server = new server($em, $port, $host); $pid = pcntl_fork(); if ($pid > 0) {    $address = $host.":".$port;    echo "server starting " . $adresse; } $server->run(); 

stop command :

$host = '127.0.0.1'; $port = 5821; $lockfile = loop::getlockfile($host.":".$port); unlink($lockfile); echo "server stopped"; 

Popular posts from this blog

node.js - How do I prevent MongoDB replica set from querying the primary? -

c# - Randomly pick a specific int from a 2D Array -

php - Angularjs http.delete is not working after deploying project on server -