Neuron-PHP

helpers.php

Table of Contents

Functions

dispatch()  : string
Dispatch a job to the queue for background processing
dispatchNow()  : mixed
Execute a job immediately (synchronously), bypassing the queue
getQueueManager()  : QueueManager
Get the queue manager instance from registry
queueSize()  : int
Get the size of a queue
clearQueue()  : int
Clear all jobs from a queue

Functions

dispatch()

Dispatch a job to the queue for background processing

dispatch(IJob $job[, array<string|int, mixed> $args = [] ][, string|null $queue = null ][, int $delay = 0 ]) : string
Parameters
$job : IJob

Job instance to queue

$args : array<string|int, mixed> = []

Arguments to pass to the job

$queue : string|null = null

Queue name (null = default)

$delay : int = 0

Delay in seconds before job is available

Tags
example

// Basic usage dispatch(new SendEmailJob(), ['to' => '[email protected]']);

// With specific queue dispatch(new ProcessImageJob(), ['path' => '/tmp/image.jpg'], 'images');

// Delayed job (run in 1 hour) dispatch(new SendReminderJob(), ['order_id' => 123], 'default', 3600);

Return values
string

Job ID

dispatchNow()

Execute a job immediately (synchronously), bypassing the queue

dispatchNow(IJob $job[, array<string|int, mixed> $args = [] ]) : mixed

Useful for testing or when you want to ensure a job runs in the current process without queueing.

Parameters
$job : IJob

Job instance to execute

$args : array<string|int, mixed> = []

Arguments to pass to the job

Tags
example

$result = dispatchNow(new ProcessDataJob(), ['data' => $data]);

Return values
mixed

Job result

getQueueManager()

Get the queue manager instance from registry

getQueueManager() : QueueManager

Creates a new instance if one doesn't exist.

Return values
QueueManager

queueSize()

Get the size of a queue

queueSize([string|null $queue = null ]) : int
Parameters
$queue : string|null = null

Queue name (null = default)

Tags
example

$size = queueSize(); // default queue $emailQueueSize = queueSize('emails');

Return values
int

Number of jobs in queue

clearQueue()

Clear all jobs from a queue

clearQueue([string|null $queue = null ]) : int
Parameters
$queue : string|null = null

Queue name (null = default)

Tags
example

$cleared = clearQueue('emails');

Return values
int

Number of jobs cleared


        
On this page

Search results