public function connect(Dog_Server $server, $blocking = 0) { if ($this->connecting) { return $this->socket_try; } $this->connecting = true; // Disconnect, so the child process has no db that it could kill. global $SINGLE_GDO_DB; $SINGLE_GDO_DB->disconnect(); $SINGLE_GDO_DB = null; $pid = pcntl_fork(); if ($pid == -1) { } else { if ($pid) { $this->server = $server; self::$PARENT_PID = $pid; if (!$this->initQueues()) { die('Cannot get message queue :('); } $this->connected = true; gdo_db(); return true; } else { $this->server = $server; // we are the child declare (ticks=1); if (false === pcntl_signal(SIGINT, array($this, 'SIGINT'))) { die('Cannot install SIGINT handler in ' . __FILE__ . PHP_EOL); } if (false === pcntl_signal(SIGCHLD, array($this, 'SIGINT'))) { die('Cannot install SIGCHLD handler in ' . __FILE__ . PHP_EOL); } if (!$this->initQueues()) { die('Cannot get message queue :('); } $this->socket = new WebSocketServer('tcp://0.0.0.0:' . $server->getPort(), 'rob_hubbard_fanclub!'); $this->socket->addObserver($this); $this->socket->initQueue((int) $server->getID()); // sleep(10); // die('oops'); if (false === $this->socket->run($this)) { $this->socket_try = false; return false; } return true; } } }