class Listener

Traits

Properties

protected string $environment

The environment the workers should run under.

protected int $sleep

The amount of seconds to wait before polling the queue.

protected int $maxTries

The number of times to try a job before logging it failed.

protected Closure|null $outputHandler

The output handler callback.

Methods

Closure|null
guardProcessOutput(Process $process, callable|null $output)

Stop the process if its output callback fails.

__construct(string $commandPath)

Create a new queue listener.

string
phpBinary()

Get the PHP binary.

string
artisanBinary()

Get the Artisan binary.

void
listen(string|null $connection, string $queue, ListenerOptions $options)

Listen to the given queue connection.

Process
makeProcess(string|null $connection, string $queue, ListenerOptions $options)

Create a new Symfony process for the worker.

array
addEnvironment(array $command, ListenerOptions $options)

Add the environment option to the given command.

array
createCommand(string|null $connection, string $queue, ListenerOptions $options)

Create the command with the listener options.

void
runProcess(Process $process, float|string $memory)

Run the given process.

void
handleWorkerOutput(string $type, string $line)

Handle output from the worker process.

bool
memoryExceeded(float|string $memoryLimit)

Determine if the memory limit has been exceeded.

never
stop()

Stop listening and bail out of the script.

void
setOutputHandler(Closure $outputHandler)

Set the output handler callback.

Details

protected Closure|null guardProcessOutput(Process $process, callable|null $output)

Stop the process if its output callback fails.

Parameters

Process $process
callable|null $output

Return Value

Closure|null

at line 43
__construct(string $commandPath)

Create a new queue listener.

Parameters

string $commandPath

at line 51
protected string phpBinary()

Get the PHP binary.

Return Value

string

at line 59
protected string artisanBinary()

Get the Artisan binary.

Return Value

string

at line 67
void listen(string|null $connection, string $queue, ListenerOptions $options)

Listen to the given queue connection.

Parameters

string|null $connection
string $queue
ListenerOptions $options

Return Value

void

at line 83
Process makeProcess(string|null $connection, string $queue, ListenerOptions $options)

Create a new Symfony process for the worker.

Parameters

string|null $connection
string $queue
ListenerOptions $options

Return Value

Process

at line 110
protected array addEnvironment(array $command, ListenerOptions $options)

Add the environment option to the given command.

Parameters

array $command
ListenerOptions $options

Return Value

array

at line 118
protected array createCommand(string|null $connection, string $queue, ListenerOptions $options)

Create the command with the listener options.

Parameters

string|null $connection
string $queue
ListenerOptions $options

Return Value

array

at line 141
void runProcess(Process $process, float|string $memory)

Run the given process.

Parameters

Process $process
float|string $memory

Return Value

void

at line 158
protected void handleWorkerOutput(string $type, string $line)

Handle output from the worker process.

Parameters

string $type
string $line

Return Value

void

at line 168
bool memoryExceeded(float|string $memoryLimit)

Determine if the memory limit has been exceeded.

Parameters

float|string $memoryLimit

Return Value

bool

at line 178
never stop()

Stop listening and bail out of the script.

Return Value

never

at line 189
void setOutputHandler(Closure $outputHandler)

Set the output handler callback.

The callback persists on the singleton listener for the command lifetime and handles every subsequent worker output line.

Parameters

Closure $outputHandler

Return Value

void