> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel queue driver

> Use StackShift Queues as a Laravel queue connection. dispatch() and php artisan queue:work keep working as they are.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## Goal

Move a Laravel app's queue onto StackShift Queues without changing job code.

## Prerequisites

* A Laravel app
* A queue with a Pull consumer
* An API key that can send to the queue
* The queue accepts text messages

## Workflow

**Step 1**

Install the PHP SDK with composer require stackshift/assets. Laravel discovers its queue service provider on its own.

**Step 2**

Add a stackshift connection to config/queue.php.

**Step 3**

Set QUEUE\_CONNECTION=stackshift and STACKSHIFT\_QUEUE\_TOKEN in your environment.

**Step 4**

Dispatch jobs as before and run php artisan queue:work stackshift.

## Install

```bash theme={null}
composer require stackshift/assets
```

## config/queue.php

* token: an API key that can send to and pull from the queue. Without it the driver uses STACKSHIFT\_QUEUE\_TOKEN, then STACKSHIFT\_API\_KEY. A pull token (sqt\_) is enough for a worker that never dispatches.
* queue: the queue name, or its id or \<project\_id>:\<name> when the name is in more than one project.
* retry\_after: the visibility timeout, in seconds, for each pulled job. Set it longer than your slowest job.
* after\_commit: Laravel's usual option to dispatch only after the database transaction commits.

```php connections theme={null}
'stackshift' => [
    'driver' => 'stackshift',
    'token' => env('STACKSHIFT_QUEUE_TOKEN', env('STACKSHIFT_API_KEY')),
    'base_url' => env('STACKSHIFT_BASE_URL', 'https://api.stackshift.cloud/api/v1'),
    'queue' => env('STACKSHIFT_QUEUE', 'orders'),
    'retry_after' => 90,
    'after_commit' => false,
],
```

## .env

```bash theme={null}
QUEUE_CONNECTION=stackshift
STACKSHIFT_QUEUE_TOKEN=...
STACKSHIFT_QUEUE=orders
```

## Jobs and workers

* dispatch() sends one text message carrying Laravel's job payload. The worker pulls one message at a time, runs the job and acks it.
* delay() and later() send the message with that delay. release(\$seconds) inside a job, or a failed attempt, retries the message with that delay. The longest delay is 24 hours.
* attempts() is the message attempts count, which includes the current delivery, so a first run shows 1.
* Dead letters follow the queue consumer's max retries and dead-letter queue. Keep the job's \$tries at or below max retries plus one.
* While delivery is paused, queue:work finds no jobs and waits.
* Run the worker as a worker service in your StackShift project, or anywhere that can reach the API.

```php theme={null}
ProcessOrder::dispatch($order);
ProcessOrder::dispatch($order)->delay(now()->addMinutes(10));
```

```bash theme={null}
php artisan queue:work stackshift
```

## Expected result

> [!TIP]
>
> Jobs dispatched by the app appear on the queue, and the worker takes them off and runs them.

## Common failures

> [!WARNING]
>
> * queue:work sits idle: the queue is paused, and a paused queue gives the worker no jobs. Resume it.
> * Sends are refused with a pull token: a pull token can only pull and ack. Use an API key in apps that dispatch.
> * later() or delay() over 24 hours throws InvalidArgumentException: 24 hours is the longest delay.
> * Jobs go to the dead-letter queue before Laravel gives up, or Laravel fails them first: keep the job's \$tries at or below the consumer's max retries plus one (max\_retries 3 allows 4 tries).

## Related guides

> [card] [Pull consumers](https://docs.stackshift.cloud/queues/pull-consumers.md)
>
> A worker anywhere pulls a batch over HTTP, leases the messages for a visibility timeout, then acks or retries each one by lease id.

> [card] [Batching, retries and delays](https://docs.stackshift.cloud/queues/batching-retries-and-delays.md)
>
> How batch size and wait, retries, retry delays, concurrency and delivery guarantees work.

> [card] [Limits and error codes](https://docs.stackshift.cloud/queues/limits-and-errors.md)
>
> Sizes, rates, retention and the error codes the Queues API returns when a limit is reached.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.