Ejemplo n.º 1
0
 public function read()
 {
     if ($this->closed) {
         return false;
     }
     $record = UltraMilk_FCGI_Record::read($this->conn);
     if (!$record) {
         return false;
     }
     if ($record->getType() === UltraMilk_FCGI_RecordTypes::ABORT_REQUEST) {
         throw new UltraMilk_FCGI_AbortRequestException();
     }
     if ($record->getRequestId() !== $this->requestId || $record->getType() !== $this->type) {
         throw new UltraMilk_FCGI_UnexpectedRecordException();
     }
     if (($content = $record->getContent()) == null) {
         $this->closed = true;
         return false;
     }
     if ($this->type == UltraMilk_FCGI_RecordTypes::PARAMS) {
         $this->content = array_merge($this->content, $content);
     } else {
         $this->content .= $content;
     }
     return $content;
 }
Ejemplo n.º 2
0
 private function createChild($socket, $count)
 {
     while ($conn = stream_socket_accept($socket, -1)) {
         while ($record = UltraMilk_FCGI_Record::read($conn)) {
             if ($record->getType() == UltraMilk_FCGI_RecordTypes::BEGIN_REQUEST) {
                 if ($record->getRole() !== $this->role) {
                     throw new RuntimeException('UltraMilk role not equal request role!');
                 }
                 if ($record->getRole() == UltraMilk_FCGI_Roles::RESPONDER) {
                     $this->onRequestHandler->invoke(new UltraMilk_HTTP_Request(UltraMilk_FCGI_Request::create($conn, $record->getVersion(), $this->role, $record->getRequestId(), $record->getFlags())));
                 } else {
                     throw new RuntimeException('This role doesn\'t supported at this moment!');
                 }
             }
             unset($record);
             if (!is_resource($conn)) {
                 break;
             }
         }
     }
 }