PHPackages                             oliverlundquist/laravel-http-background - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. oliverlundquist/laravel-http-background

ActiveLibrary[HTTP &amp; Networking](/categories/http)

oliverlundquist/laravel-http-background
=======================================

Non-Blocking HTTP Requests in Laravel.

1.0.0(9mo ago)66MITPHPPHP ^8.2CI passing

Since Jul 16Pushed 9mo agoCompare

[ Source](https://github.com/oliverlundquist/laravel-http-background)[ Packagist](https://packagist.org/packages/oliverlundquist/laravel-http-background)[ RSS](/packages/oliverlundquist-laravel-http-background/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (9)Versions (4)Used By (0)

Laravel HTTP Background
=======================

[](#laravel-http-background)

[![PHPUnit](https://github.com/oliverlundquist/laravel-http-background/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/oliverlundquist/laravel-http-background/actions/workflows/phpunit.yml)[![Coverage](https://raw.githubusercontent.com/oliverlundquist/laravel-http-background/refs/heads/image-data/coverage.svg)](https://github.com/oliverlundquist/laravel-http-background/actions/workflows/coverage.yml)[![PHPStan](https://github.com/oliverlundquist/laravel-http-background/actions/workflows/phpstan.yml/badge.svg?branch=master)](https://github.com/oliverlundquist/laravel-http-background/actions/workflows/phpstan.yml)[![PHP-CS-Fixer](https://github.com/oliverlundquist/laravel-http-background/actions/workflows/php-cs-fixer.yml/badge.svg?branch=master)](https://github.com/oliverlundquist/laravel-http-background/actions/workflows/php-cs-fixer.yml)

Moves HTTP Requests out from PHP to a forked process on the server executing the request through cURL and then piping the results back into a Laravel Artisan command that fires events about the status of the response of the request. This enables PHP to execute without having to wait for responses from its HTTP requests, enabling one server instance to handle lots of outgoing HTTP requests without using many resources or blocking the execution of PHP. In my tests, 10 concurrent requests had a peak memory usage of only 40mb.

I wrote a blog about this package where I go into more detail about the motivation behind it and alternative methods that I tried before going down the route of forking HTTP requests into separate processes. It's available \[[here](https://oliverlundquist.com/2025/07/20/performing-http-requests-in-background.html)\].

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

[](#installation)

```
composer require oliverlundquist/laravel-http-background

```

Usage
-----

[](#usage)

```
// use it directly
HttpBg::get('https://httpbin.org/get');
HttpBg::head('https://httpbin.org/head');
HttpBg::post('https://httpbin.org/post', json_encode(['json' => 'payload']));
HttpBg::patch('https://httpbin.org/patch', json_encode(['json' => 'payload']));
HttpBg::put('https://httpbin.org/put', json_encode(['json' => 'payload']));
HttpBg::delete('https://httpbin.org/delete');

// or though a macro registered on the Laravel HTTP Client
Http::background()->get('https://httpbin.org/get');
Http::background()->head('https://httpbin.org/head');
Http::background()->post('https://httpbin.org/post', json_encode(['json' => 'payload']));
Http::background()->patch('https://httpbin.org/patch', json_encode(['json' => 'payload']));
Http::background()->put('https://httpbin.org/put', json_encode(['json' => 'payload']));
Http::background()->delete('https://httpbin.org/delete');
```

Options
-------

[](#options)

#### -&gt;connectionTimeout()

[](#-connectiontimeout)

Timeout to establish a connection (in seconds).

```
HttpBg::connectTimeout(10);
Http::background()->connectTimeout(10);
```

#### -&gt;timeout()

[](#-timeout)

Maximum time allowed for the whole request (in seconds).

```
HttpBg::timeout(30);
Http::background()->timeout(30);
```

#### -&gt;retry()

[](#-retry)

Max attempts that this request can be retried, see the implementation example below.

```
HttpBg::retry(3);
Http::background()->retry(3);
```

#### -&gt;setRequestTag()

[](#-setrequesttag)

Arbitrary data used to identify the request.

```
HttpBg::setRequestTag('webhook callback for id: 31');
Http::background()->setRequestTag('webhook callback for id: 31');
```

#### -&gt;contentType()

[](#-contenttype)

Set the Content-Type header.

```
HttpBg::contentType('application/json');
Http::background()->contentType('application/json');
```

#### -&gt;accept()

[](#-accept)

Set the Accept header.

```
HttpBg::accept('application/json');
Http::background()->accept('application/json');
```

#### -&gt;withBody()

[](#-withbody)

Set the body of the request, this can also be set implicitly by calling any of the HTTP verb short-hand methods `->post()`, `->patch()`, `->put()`, `->delete()`. The withBody() method can also set the Content-Type and Accept headers by providing values for the second and third arguments.

```
$contentType = 'application/json';
$accept      = 'application/json';
HttpBg::withBody(json_encode(['json' => 'payload']), $contentType, $accept);
Http::background()->withBody(json_encode(['json' => 'payload']), $contentType, $accept);
```

#### -&gt;queue()

[](#-queue)

Push the request to the Laravel Queue and fork a process on your queue worker server instance instead of your main PHP application server. This is useful if you don't want forked processes on your application server but rather have them processed on your server instance running the queue worker.

```
HttpBg::queue()->get('https://httpbin.org/get');
Http::background()->queue()->get('https://httpbin.org/get');
```

#### -&gt;processIsRunning()

[](#-processisrunning)

Check whether the background process (pid) is still running.

```
$request = HttpBg::get('https://httpbin.org/get');
$request = Http::background()->get('https://httpbin.org/get');

$request->processIsRunning();
```

Events
------

[](#events)

Events are fired to track the progress and result of the request.

```
Event::listen(function (HttpBgRequestSending $event)  { Log::info($event->request); });
Event::listen(function (HttpBgRequestSent $event)     { Log::info($event->request); });
Event::listen(function (HttpBgRequestSuccess $event)  { Log::info($event->requestId); });
Event::listen(function (HttpBgRequestFailed $event)   { Log::info($event->requestId); });
Event::listen(function (HttpBgRequestTimeout $event)  { Log::info($event->requestId); });
Event::listen(function (HttpBgRequestComplete $event) { Log::info($event->requestId); });
```

Implementation Example
----------------------

[](#implementation-example)

This is an example of a basic implementation that handles request retries and sends notifications of failed and timed-out requests by mail.

```
class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Event::listen(function (HttpBgRequestSent $event) {
            $request = $event->request;
            Cache::put($request->id, $request->toArray());
        });

        Event::listen(function (HttpBgRequestFailed|HttpBgRequestTimeout $event) {
            $requestId = $event->requestId;
            $request   = HttpBgRequest::newFromArray(Cache::get($requestId, []));

            if (! $request->validateRequest()) {
                return;
            }
            if ($request->maxAttempts > $request->attempts) {
                HttpBg::send($request);
                return;
            }
            Cache::forget($requestId);
            Mail::to('integration@partner.com')
                ->send(new FailedWebHookMail($request->tag));
        });
    }
}
```

Windows Users
-------------

[](#windows-users)

PowerShell is currently not supported. However, adding support shouldn't be too difficult, since the cURL arguments are mostly the same - just replace -o /dev/null with -o NUL.

I'm not a PowerShell expert, but I believe something like (Start-Job { &amp; command }).Id could be used to retrieve the job ID. You could then check the job status later using Get-Job -Id $id.

If you're interested in contributing PowerShell support, feel free to open a pull request!

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance56

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

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

Every ~2 days

Total

3

Last Release

293d ago

Major Versions

0.0.2 → 1.0.02025-07-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce332567068cbe0f67c880f80e11821ce6c646e1299759c237023f15293abbb3?d=identicon)[oliverlundquist](/maintainers/oliverlundquist)

---

Top Contributors

[![oliverlundquist](https://avatars.githubusercontent.com/u/8519153?v=4)](https://github.com/oliverlundquist "oliverlundquist (7 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/oliverlundquist-laravel-http-background/health.svg)

```
[![Health](https://phpackages.com/badges/oliverlundquist-laravel-http-background/health.svg)](https://phpackages.com/packages/oliverlundquist-laravel-http-background)
```

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[mateusjunges/laravel-kafka

A kafka driver for laravel

7163.1M17](/packages/mateusjunges-laravel-kafka)[illuminate/notifications

The Illuminate Notifications package.

483.0M964](/packages/illuminate-notifications)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)

PHPackages © 2026

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