Starting Pure PHP socket in Backend/Asynchronously -
i have created php socket ios app. , working when starting using terminal before doing work..
the problem first socket_write.
before writing, check if socket of server running.. $result = socket_connect($socket, $address, $service_port);
if false need redirect page http://localhost/api3/server.php start socket
public function __socket_write($text) {     $result = socket_connect($socket, $address, $service_port);      if ($result === false)      {         // if failed connect means server down/not running         $this->__socket_start("http://localhost/api3/server.php");     }     // codes here not called api got time out error well, must have been    redirected completely? }  public function __socket_start($url, $status_code = 303) {    header('location: '.$url, true, $status_code); }   the server started looks need call __socket_start() asynchronously able execute codes below $this->__socket_start() don't know how, , after while socket server closed again... 
when start socket using terminal php server.php, doesn't disconnect.
thank in advance...
solved this, not 1 want do, it's working intended first place..
here how looks now:
public function __socket_write($text) {     $service_port = xxxxxx;      $address = myaddress;      $socket = socket_create(af_inet, sock_stream, sol_tcp);      $result = socket_connect($socket, $address, $service_port);      if ($result === false)      {         $this->__socket_start();     }       @socket_listen($socket);      ...      socket_close($socket); }  public function __socket_start() {     $cmd = "php server.php";      shell_exec($cmd." > /dev/null 2>/dev/null &"); }      
Comments
Post a Comment