Protocol\FCGI\Record::unpack PHP Method

unpack() final public static method

Unpacks the message from the binary data buffer
final public static unpack ( string $data ) : static
$data string Binary buffer with raw data
return static
    public static final function unpack($data)
    {
        $self = new static();
        list($self->version, $self->type, $self->requestId, $self->contentLength, $self->paddingLength, $self->reserved) = array_values(unpack(FCGI::HEADER_FORMAT, $data));
        $payload = substr($data, FCGI::HEADER_LEN);
        self::unpackPayload($self, $payload);
        if (get_called_class() !== __CLASS__ && $self->contentLength > 0) {
            static::unpackPayload($self, $payload);
        }
        return $self;
    }

Usage Example

Ejemplo n.º 1
0
 public function testPackingPacket()
 {
     $record = new Record();
     $record->setRequestId(5);
     $record->setContentData('12345');
     $packet = (string) $record;
     $this->assertEquals($packet, hex2bin('010b0005000503003132333435000000'));
     $result = Record::unpack($packet);
     $this->assertEquals($result->getType(), FCGI::UNKNOWN_TYPE);
     $this->assertEquals($result->getRequestId(), 5);
     $this->assertEquals($result->getContentData(), '12345');
 }