Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

CgiInputStream
in package

php:// stream wrapper for the CGI subprocesses (proc cgi_worker.php and the pooled pool_worker.php).

It serves php://input from the CURRENT request's raw body, stashed in $GLOBALS['__zeal_cgi_raw_input'] by the worker before the target file runs. This bridges an OpenSwoole-delivered request body (e.g. the JSON payload the WordPress block editor PUT/POSTs to the REST API) to legacy code that reads file_get_contents('php://input') — which native CLI php://input does NOT provide. Every other php:// stream (memory/temp/filter/fd/…) passes through to the default wrapper unchanged.

Counterpart to \ZealPHP\IOStreamWrapper (in-process modes, body from RequestContext). String-backed for input (no php://memory round-trip).

NOTE: $context is RESERVED — PHP injects the stream context resource into it, so it must never be fclose()'d. The passthrough handle lives in $fh.

Table of Contents

Properties

$context  : resource|null
$fh  : resource|null
$input  : string
$isInput  : bool
$pos  : int

Methods

stream_close()  : void
Close the stream, releasing the passthrough handle when one was opened for a non-input php:// URI.
stream_eof()  : bool
Returns true when all php://input bytes are consumed, or when the passthrough handle is at EOF.
stream_open()  : bool
Open php://input from $GLOBALS['__zeal_cgi_raw_input'], or delegate any other php:// URI to the default PHP wrapper by temporarily restoring it.
stream_read()  : string|false
Read up to $count bytes. Returns '' when $count < 1 on the php://input path.
stream_seek()  : bool
Seek to a position; supports SEEK_SET, SEEK_CUR, SEEK_END on the php://input buffer.
stream_set_option()  : bool
No-op option handler — always returns true to suppress PHP "not implemented" warnings.
stream_stat()  : array<int|string, mixed>|false
Return stat information. For php://input provides a minimal array with 'size'; for passthrough handles delegates to fstat().
stream_tell()  : int
Return the current read position in bytes from the start of the stream.
stream_write()  : int|false
Write $data to the passthrough handle (not applicable to php://input).

Properties

$context

public resource|null $context

PHP-injected stream context (reserved; never fclose).

$fh

private resource|null $fh = null

Passthrough handle for non-input php:// streams.

Methods

stream_close()

Close the stream, releasing the passthrough handle when one was opened for a non-input php:// URI.

public stream_close() : void

stream_eof()

Returns true when all php://input bytes are consumed, or when the passthrough handle is at EOF.

public stream_eof() : bool
Return values
bool

stream_open()

Open php://input from $GLOBALS['__zeal_cgi_raw_input'], or delegate any other php:// URI to the default PHP wrapper by temporarily restoring it.

public stream_open(string $path, string $mode, int $options, string|null &$opened_path) : bool
Parameters
$path : string

The php:// URI being opened.

$mode : string

The access mode (e.g. 'r', 'rb').

$options : int

Bitmask of STREAM_* flags from PHP.

$opened_path : string|null

Set to the actual path opened (unused here).

Return values
bool

stream_read()

Read up to $count bytes. Returns '' when $count < 1 on the php://input path.

public stream_read(int $count) : string|false
Parameters
$count : int

Number of bytes to read.

Return values
string|false

The bytes read, or false when the passthrough handle is gone.

stream_seek()

Seek to a position; supports SEEK_SET, SEEK_CUR, SEEK_END on the php://input buffer.

public stream_seek(int $offset[, int $whence = SEEK_SET ]) : bool
Parameters
$offset : int

Byte offset relative to $whence.

$whence : int = SEEK_SET

One of SEEK_SET, SEEK_CUR, or SEEK_END.

Return values
bool

stream_set_option()

No-op option handler — always returns true to suppress PHP "not implemented" warnings.

public stream_set_option(int $option, int $arg1, int $arg2) : bool
Parameters
$option : int

One of the STREAM_OPTION_* constants.

$arg1 : int

Option-specific argument 1.

$arg2 : int

Option-specific argument 2.

Return values
bool

stream_stat()

Return stat information. For php://input provides a minimal array with 'size'; for passthrough handles delegates to fstat().

public stream_stat() : array<int|string, mixed>|false
Return values
array<int|string, mixed>|false

Stat array, or false when unavailable.

stream_tell()

Return the current read position in bytes from the start of the stream.

public stream_tell() : int
Return values
int

Byte offset.

stream_write()

Write $data to the passthrough handle (not applicable to php://input).

public stream_write(string $data) : int|false
Parameters
$data : string

The bytes to write.

Return values
int|false

Number of bytes written, or false when no passthrough handle is open.

On this page