class StdioTransport implements Transport

Constants

protected STDERR_LIMIT

Properties

protected Process|null $process
protected StdioInput|null $input
protected string $buffer
protected string $stderr
protected float $timeoutSeconds

Methods

__construct(string $command, array $args = [], array $env = [])

Create a subprocess transport.

void
connect()

Start the subprocess if it is not already running.

void
disconnect()

Detach the owned state and stop the subprocess.

void
setTimeoutSeconds(float $seconds)

Set the maximum idle time while awaiting a response.

array
recipe()

Get the configuration needed to recreate this transport.

void
send(string $message, array $headers = [])

Write a newline-delimited protocol message.

string
receive()

Receive the next complete protocol message.

string
readNextLine(Process $process)

Read retained and incoming output until a complete message is available.

void
drainErrorOutput(Process $process)

Retain a bounded diagnostic tail without leaving stderr in the process buffer.

bool
bufferUntilNewline(string $type, string $chunk)

Append standard output and detect a complete message.

string|null
popLine()

Remove the next complete line from the retained output.

never
failWith(string $message)

Disconnect and report a transport failure.

__destruct()

Disconnect any remaining subprocess.

Details

at line 38
__construct(string $command, array $args = [], array $env = [])

Create a subprocess transport.

Parameters

string $command
array $args
array $env

at line 45
void connect()

Start the subprocess if it is not already running.

Return Value

void

at line 68
void disconnect()

Detach the owned state and stop the subprocess.

Return Value

void

at line 85
void setTimeoutSeconds(float $seconds)

Set the maximum idle time while awaiting a response.

Parameters

float $seconds

Return Value

void

at line 95
array recipe()

Get the configuration needed to recreate this transport.

Return Value

array

at line 111
void send(string $message, array $headers = [])

Write a newline-delimited protocol message.

Parameters

string $message
array $headers

Return Value

void

at line 130
string receive()

Receive the next complete protocol message.

Return Value

string

at line 142
protected string readNextLine(Process $process)

Read retained and incoming output until a complete message is available.

Parameters

Process $process

Return Value

string

at line 187
protected void drainErrorOutput(Process $process)

Retain a bounded diagnostic tail without leaving stderr in the process buffer.

Parameters

Process $process

Return Value

void

at line 197
protected bool bufferUntilNewline(string $type, string $chunk)

Append standard output and detect a complete message.

Parameters

string $type
string $chunk

Return Value

bool

at line 211
protected string|null popLine()

Remove the next complete line from the retained output.

Return Value

string|null

at line 228
protected never failWith(string $message)

Disconnect and report a transport failure.

Parameters

string $message

Return Value

never

at line 250
__destruct()

Disconnect any remaining subprocess.