PHPackages                             ossycodes/laravel-cloudflare-queue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. ossycodes/laravel-cloudflare-queue

ActiveLibrary[Queues &amp; Workers](/categories/queues)

ossycodes/laravel-cloudflare-queue
==================================

A production-ready Cloudflare Queue driver for Laravel, implementing the full Queue contract.

v1.0.0(1mo ago)701[2 PRs](https://github.com/ossycodes/laravel-cloudflare-queue/pulls)MITPHPPHP ^8.1

Since May 30Pushed 1mo agoCompare

[ Source](https://github.com/ossycodes/laravel-cloudflare-queue)[ Packagist](https://packagist.org/packages/ossycodes/laravel-cloudflare-queue)[ RSS](/packages/ossycodes-laravel-cloudflare-queue/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

Laravel Cloudflare Queue
========================

[](#laravel-cloudflare-queue)

A production-ready Cloudflare Queue driver for Laravel that implements the full Queue contract, fixing all known issues with existing community packages.

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, or 12
- Cloudflare account with a Queue created
- Cloudflare API token with **Queues Read** and **Queues Write** permissions

Installation
------------

[](#installation)

```
composer require ossycodes/laravel-cloudflare-queue
```

The service provider is auto-discovered via Laravel's package discovery.

Configuration
-------------

[](#configuration)

Add a connection entry to `config/queue.php`:

```
'connections' => [

    'cloudflare' => [
        'driver'               => 'cloudflare',
        'account_id'           => env('CLOUDFLARE_ACCOUNT_ID'),
        'queue_id'             => env('CLOUDFLARE_QUEUE_ID'),
        'api_token'            => env('CLOUDFLARE_API_TOKEN'),

        // Number of messages to pull per poll cycle (default: 1)
        // Increase this to reduce API calls when processing at volume.
        // Set visibility_timeout_ms high enough to cover:
        //   batch_size × average job processing time
        'batch_size'           => env('CLOUDFLARE_QUEUE_BATCH_SIZE', 1),

        // How long a pulled message is hidden from other consumers (ms, default: 30000)
        // Must be > batch_size × average processing time to prevent duplicate processing.
        'visibility_timeout_ms' => env('CLOUDFLARE_QUEUE_VISIBILITY_TIMEOUT_MS', 30000),

        // Dispatch jobs after the current database transaction commits (default: false)
        'after_commit'         => false,

        // Optional: class to handle raw messages pushed by a Cloudflare Worker
        // (not by Laravel's own Queue::push). Leave null for standard Laravel jobs.
        'raw_handler'          => null,
    ],

],
```

Add the corresponding `.env` variables:

```
CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_QUEUE_ID=your-queue-id
CLOUDFLARE_API_TOKEN=your-api-token
```

Set as the default queue driver:

```
QUEUE_CONNECTION=cloudflare
```

Usage
-----

[](#usage)

### Dispatching Standard Laravel Jobs

[](#dispatching-standard-laravel-jobs)

Works exactly like any other Laravel queue driver:

```
// Dispatch immediately
MyJob::dispatch($data);

// Dispatch with a delay
MyJob::dispatch($data)->delay(now()->addMinutes(5));

// Dispatch multiple jobs
Queue::bulk([new JobA(), new JobB()]);
```

### Processing Jobs

[](#processing-jobs)

```
php artisan queue:work cloudflare
php artisan queue:work cloudflare --sleep=3 --tries=3
```

### Batch Processing (Reducing API Calls)

[](#batch-processing-reducing-api-calls)

Set `batch_size` &gt; 1 to pull multiple messages per API call. The driver buffers pulled messages in memory and returns them one-by-one to Laravel's worker loop — so the API is only called when the buffer is empty, not on every job.

```
// config/queue.php
'cloudflare' => [
    'batch_size'            => 10,
    'visibility_timeout_ms' => 60_000, // 60s — must cover 10 × avg job time
],
```

> **Important:** `visibility_timeout_ms` must be large enough to cover `batch_size × average_job_processing_time`. If jobs in the buffer expire before they're processed, Cloudflare will make them visible again, causing duplicate processing.

### Handling Raw Messages from a Cloudflare Worker

[](#handling-raw-messages-from-a-cloudflare-worker)

If you push messages from a Cloudflare Worker (not from Laravel), the message body won't follow Laravel's job serialization format. Use `raw_handler` to route these messages to a specific class:

**Cloudflare Worker (producer):**

```
await env.MY_QUEUE.send({ email_to: "user@example.com", subject: "Hello" });
```

**Laravel config:**

```
'cloudflare' => [
    'raw_handler' => App\Jobs\HandleWorkerEmail::class,
],
```

**Handler class:**

```
class HandleWorkerEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    public function __construct(public readonly array $data) {}

    public function handle(): void
    {
        // $this->data = ['email_to' => 'user@example.com', 'subject' => 'Hello']
        Mail::to($this->data['email_to'])->send(new MyMail($this->data));
    }
}
```

### `after_commit`

[](#after_commit)

When `after_commit` is `true`, jobs dispatched inside a database transaction won't be placed on the queue until the transaction successfully commits. This prevents a race where the worker picks up the job before the DB write is visible.

```
'after_commit' => true,
```

Known Limitations
-----------------

[](#known-limitations)

### Queue Clearing Not Supported

[](#queue-clearing-not-supported)

The Cloudflare Queues REST API does not expose a purge endpoint for consumers. Calling `Queue::clear()` or `php artisan queue:clear cloudflare` will throw a `RuntimeException`.

To clear a queue, use:

- The Cloudflare Dashboard → Queues → select queue → Purge
- Or the Wrangler CLI: `wrangler queues purge `

### Job Inspection (Laravel Horizon)

[](#job-inspection-laravel-horizon)

Cloudflare Queues does not expose individual job listings via the REST API. The following methods return empty collections (same behaviour as SQS and Beanstalkd):

- `pendingJobs()`, `delayedJobs()`, `reservedJobs()`
- `allPendingJobs()`, `allDelayedJobs()`, `allReservedJobs()`

`pendingSize()` returns the total message backlog count from the queue metadata. `delayedSize()` and `reservedSize()` return 0.

Laravel Horizon is **not fully supported**.

### Delayed Jobs

[](#delayed-jobs)

Cloudflare Queues supports `delay_seconds` up to the queue's maximum delay (currently 12 hours). Delayed jobs work via `->delay()` or `Queue::later()`.

### No Blocking Pop

[](#no-blocking-pop)

Unlike Redis and Beanstalkd, Cloudflare Queues does not support long-polling. The worker will poll every `--sleep` seconds when the queue is empty.

Running Tests
-------------

[](#running-tests)

```
composer install
./vendor/bin/pest
./vendor/bin/pest --coverage
```

License
-------

[](#license)

MIT

How do I say Thank you?
-----------------------

[](#how-do-i-say-thank-you)

Please buy me a cup of coffee  , Leave a star and follow me on [Twitter](https://twitter.com/ossycodes) .

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance89

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

55d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/82932703b154706ffc400d8319ed794db6567b1c2cb4f862cde814b0e442b88f?d=identicon)[ossycodes](/maintainers/ossycodes)

---

Top Contributors

[![ossycodes](https://avatars.githubusercontent.com/u/55060799?v=4)](https://github.com/ossycodes "ossycodes (24 commits)")

---

Tags

laravelqueuedrivercloudflare

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/ossycodes-laravel-cloudflare-queue/health.svg)

```
[![Health](https://phpackages.com/badges/ossycodes-laravel-cloudflare-queue/health.svg)](https://phpackages.com/packages/ossycodes-laravel-cloudflare-queue)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11223.5M33](/packages/anourvalar-eloquent-serialize)[mpbarlow/laravel-queue-debouncer

A wrapper job for debouncing other queue jobs.

63825.7k1](/packages/mpbarlow-laravel-queue-debouncer)[convenia/pigeon

3334.8k](/packages/convenia-pigeon)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[lokielse/laravel-mns

Aliyun MNS Queue Driver For Laravel

2614.9k](/packages/lokielse-laravel-mns)[tochka-developers/queue-promises

Promises for Laravel queue jobs

1912.3k](/packages/tochka-developers-queue-promises)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
