Exemplo n.º 1
0
 /**
  * Callback for when server should be shut down
  *
  * @return vid
  */
 public static function shutdown()
 {
     $c = new Socket(self::$bindAddress[0], self::$bindAddress[1]);
     $c->connect();
     $c->write("HALT\n");
     $c->close();
 }
 /**
  * Callback for when server should be shut down
  */
 public static function shutdown()
 {
     $s = new Socket(self::$bindAddress[0], self::$bindAddress[1]);
     $s->connect();
     $s->write(pack('Nc4Na*', DEFAULT_PROTOCOL_MAGIC_NUMBER, 1, 0, 61, false, 0, null));
     $s->close();
 }
 /**
  * Send a HTTP header message
  *
  * @param   peer.Socket socket
  * @param   int sc the status code
  * @param   string message status message
  * @param   string[] headers
  */
 protected function sendHeader(Socket $socket, $sc, $message, array $headers)
 {
     $socket->write('HTTP/1.1 ' . $sc . ' ' . $message . "\r\n");
     $socket->write('Date: ' . gmdate('D, d M Y H:i:s T') . "\r\n");
     $socket->write("Server: XP/PHP\r\n");
     $socket->write("Connection: close\r\n");
     foreach ($headers as $header) {
         $socket->write($header . "\r\n");
     }
     $socket->write("\r\n");
 }
 /**
  * Send a HTTP header message
  *
  * @param   peer.Socket socket
  * @param   int sc the status code
  * @param   string message status message
  * @param   [:var] headers
  * @return  int
  */
 protected function sendHeader(Socket $socket, $sc, $message, array $headers)
 {
     $socket->write('HTTP/1.1 ' . $sc . ' ' . $message . "\r\n");
     $socket->write('Date: ' . gmdate('D, d M Y H:i:s T') . "\r\n");
     $socket->write('Server: XP/PHP ' . phpversion() . "\r\n");
     $socket->write("Connection: close\r\n");
     foreach ($headers as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $val) {
                 $socket->write($key . ': ' . $val . "\r\n");
             }
         } else {
             $socket->write($key . ': ' . $value . "\r\n");
         }
     }
     $socket->write("\r\n");
     return $sc;
 }
 public static function shutdownServer()
 {
     // Tell the server to shut down
     try {
         $c = new Socket(self::$bindAddress[0], self::$bindAddress[1]);
         $c->connect();
         $c->write("HALT\n");
         $c->close();
     } catch (\lang\Throwable $ignored) {
         // Fall through, below should terminate the process anyway
     }
     $status = self::$serverProcess->out->readLine();
     if (!strlen($status) || '+' != $status[0]) {
         while ($l = self::$serverProcess->out->readLine()) {
             $status .= $l;
         }
         while ($l = self::$serverProcess->err->readLine()) {
             $status .= $l;
         }
         self::$serverProcess->close();
         throw new \lang\IllegalStateException($status);
     }
     self::$serverProcess->close();
 }