Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Web Push Laravel Package

minishlink/web-push

PHP library to send Web Push notifications to browser push endpoints (RFC 8030). Handles VAPID and payload encryption, supports batching and reporting, and works with modern PHP (8.2+) via Composer for integrating push into your backend.

View on GitHub
Deep Wiki
Context7
v11.0.0

Migration

WebPush now depends on standard interfaces instead of Guzzle directly. Any PSR-18 client now works.

If you already have guzzlehttp/guzzle installed and call new WebPush(...) with no client-related arguments: no code changes needed. php-http/discovery auto-detects Guzzle and uses it. If you use flushPooled(), you now need one extra package, see below.

If you pass the old $timeout / $clientOptions constructor arguments, you must update that call.

Constructor signature change

Before:

public function __construct(
      array $auth = [],
      array $defaultOptions = [],
      ?int $timeout = 30,
      array $clientOptions = [],
      ?LoggerInterface $logger = null
)

After:

public function __construct(
      array $auth = [],
      array $defaultOptions = [],
      ?ClientInterface $client = null,          // PSR-18
      ?RequestFactoryInterface $requestFactory = null, // PSR-17
      ?StreamFactoryInterface $streamFactory = null,   // PSR-17
      ?HttpAsyncClient $asyncClient = null,     // HTTPlug, optional, only needed for flushPooled()
      ?LoggerInterface $logger = null
)

$timeout and $clientOptions are replaced by configuring your client instance directly:

Before:

$timeout = 20;
$clientOptions = [\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => false];
$webPush = new WebPush([], [], $timeout, $clientOptions);

After:

$client = new \GuzzleHttp\Client([
      'timeout' => 20,
      \GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => false,
]);
$webPush = new WebPush([], [], $client);

If you were relying on the default (new WebPush()), nothing changes.

Keeping flushPooled() concurrency

flushPooled() used Guzzle's Pool for real concurrent requests. PSR-18 has no concept of concurrency, so this now requires an HTTPlug async client: composer require php-http/guzzle7-adapter (if you use guzzle)

The requestConcurrency option is no longer used, HTTPlug async clients manage their own concurrency (e.g. php-http/guzzle7-adapter delegates to Guzzle's MultiCurl handler).

Using a different PSR-18 client entirely

composer remove guzzlehttp/guzzle
composer require symfony/http-client nyholm/psr7
$psr18Client = new \Symfony\Component\HttpClient\Psr18Client();
$webPush = new WebPush([], [], $psr18Client, $psr18Client, $psr18Client);

For concurrent sending with a non-Guzzle stack (flushPooled), check the php-http adapter list for an HTTPlug adapter matching your client; otherwise use flush().

What's Changed

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v10.1.0...v11.0.0

v10.1.0

What's Changed

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v10.0.3...v10.1.0

v10.0.3

What's Changed

  • fix: base 64 errors introduced in v10.0.2. See #449

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v10.0.2...v10.0.3

v10.0.2

What's Changed

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v10.0.1...v10.0.2

v10.0.1
v10.0.0

What's Changed

⚠️ Breaking changes

  • Drop support for PHP 8.1

PRs

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v9.0.4...v10.0.0

v9.0.4

What's Changed

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v9.0.3...v9.0.4

v9.0.2

What's Changed

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v9.0.1...v9.0.2

v9.0.1

What's Changed

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v9.0.0...v9.0.1

v9.0.0

What's Changed

⚠️ Breaking changes

  • Dropped support for PHP 8.0
  • Dropped support of environments without a version of openssl with elliptic curve support
  • The MAX_COMPATIBILITY_PAYLOAD_LENGTH has been decreased to 2820 (see https://github.com/web-push-libs/web-push-php/issues/108). If your payloads are longer, you might want to customize the encrypted payload length based on the endpoint for strict security.

PRs

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v8.0.0...v9.0.0

v9.0.0-rc2

What's Changed

⚠️ Breaking changes

In this release candidate:

  • Dropped support for PHP 8.0
  • Dropped support of environments without a version of openssl with elliptic curve support
  • The MAX_COMPATIBILITY_PAYLOAD_LENGTH has been decreased to 2820 (see https://github.com/web-push-libs/web-push-php/issues/108). If your payloads are longer, you might want to customize the encrypted payload length based on the endpoint for strict security.

In the final version v9.0.0, there will be additional breaking changes with PR #394:

  • Change default encoding to aes128gcm
  • Change Subscription interface
  • Remove legacy GCM
  • Remove old Chrome subscription support

PRs

See also v9.0.0-rc1

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v9.0.0-rc1...v9.0.0-rc2

v9.0.0-rc1

What's Changed

⚠️ Breaking changes

In this release candidate:

  • Dropped support for PHP 8.0
  • Dropped support of environments without a version of openssl with elliptic curve support

In the final version v9.0.0, there will be additional breaking changes with PR #394:

  • Change default encoding to aes128gcm
  • Change Subscription interface
  • Remove legacy GCM
  • Remove old Chrome subscription support

PRs

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v8.0.0...v9.0.0-rc1

v8.0.0

What's Changed

The only breaking change is dropping support for PHP 7, which is not maintained anymore. (thanks @Rotzbua!)

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v7.0.0...v8.0.0

v7.0.0

What's Changed

There is no breaking change apart PHP 7.2 being now unsupported. @marc1706 did an awesome job bringing back CI testing on the repo, it means pull requests are now easily mergeable. If you have ideas for the library, now is a great time to contribute! (please propose small iterative changes 🙂)

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v6.0.7...v7.0.0

v6.0.6

What's Changed

New Contributors

Full Changelog: https://github.com/web-push-libs/web-push-php/compare/v6.0.5...v6.0.6

v6.0.5
  • PHP 8 doesn't throw notices anymore for openssl_pkey_free (thx @smujaddid!)
  • Fix error when HTTP call errored with a ConnectException instead of a RequestException (thx @rupamjbordoloi!) (see root cause)
v6.0.4
  • Methods are now protected so that users can customize more easily the client (thx @Kingdutch) (see here for ReactPHP example)
v6.0.3
  • Fixes creating local key in pure PHP with BigInteger when openssl local key creation fails (#304 #301) (thx @Spomky @rfool)
v6.0.2

You might want to use v5 since the encryption sometimes fails on certain machines. @Spomky is currently looking at this.

v6.0.1
  • Support Guzzle 7 (and thus Laravel 8) (thx @martijnb92!) : a specific PR to decouplate web-push-php from Guzzle and use psr/http-client is most welcome 🙏🏻
  • Hotfix for encryption (thx @Spomky!)
v6.0.0
  • [Breaking Change] New API : sendOneNotification and queueNotification (see Usage in README)
  • [Breaking Change] PHP 7.2+ is now required
  • Upgrade web-token dependency (thx @baer95!)
  • Remove deprecated GCM auth support (thx @BR0kEN-!)
v5.2.5
  • Added SubscriptionInterface (thx @BR0kEN-!)
v5.2.4
  • Encode VAPID key in URL-safe base64 (thx @vockalimo!)
v5.2.3
  • Removed var_dump that could be triggered in case of encryption error (thx @zmotso!)
v5.2.2
  • Don't include VAPID headers if there are no content encoding in the subscription
v5.2.1
  • FCM now supports AES128GCM on fcm/send endpoints, so the endpoint is no longer replaced with wp
v5.2.0
  • added ability to cache VAPID headers in a request (thx @javiermarinros!)
  • enhanced message reporting (thx @t1gor!)
  • made flush really async (thx @marcvdm!)
  • fixed an encryption error that would occur when using the new subscription structure with a contentEncoding (thx @soerenuhrbach!)
  • fixed an error that would occur if network request failed (thx @steffenweber!)
  • fixed some static errors
v5.1.0
  • Allow client subscription structure to be directly passed to create (thx @maglnet!)
v5.0.0

Breaking changes

You now need to iterate over the results of flush in order to actually send the notifications.

The way you handle the results of the flush() method should be changed. In v5 the flush always returns a Generator object. This means that you can still iterate over it, but you wouldn't be able to store it, at least not as-is. Using the example from the docs, the responses would now look different:

PLEASE NOTE: \Generator is returned even if you only send one message.

BEFORE:

$res = [
    [ // first notification (failed)
        'success' => false,
        'endpoint' => $theEndpointToDeleteInYourDatabaseIfExpired,
        'message' => $responseMessage,
        'statusCode' => $responseStatusCode,
        'headers' => $responseHeaders,
        'content' => $responseContent, // you may have more infos here
        'expired' => $isTheEndpointWrongOrExpired,
    ],
    [ // second notification (succeeded)
        'success' => true,
    ],
    [ // third notification
        ...
    ], ...
];

AFTER:

var_dump($res); // \Generator

/** \Minishlink\WebPush\MessageSentReport */
foreach ($res as $result) {
    // you now have access to request & response objects

    /** [@var](https://github.com/var) \Psr\Http\Message\RequestInterface $request */
    $request = $result-> getRequest();
    /** [@var](https://github.com/var) \Psr\Http\Message\ResponseInterface $response */
    $response = $result->getResponse();

    if ($result->isSuccess()) {
        // process successful message sent
        $logger->log('Notification with payload %s successfully sent for endpoint %s.' [
            json_decode((string) $response->getBody()),
            $result->getEndpoint()
        ]);
    } else {
        // or a failed one - check expiration first
        if ($result->isSubscriptionExpired()) {
            // this is just an example code, not included in library!
            $db->markExpired($result->getEndpoint());
        } else {
            // process faulty message
            $logger->log('Notification failed: %s. Payload: %s, endpoint: %s' [
                $result->getReason(),
                json_decode((string) $response->getBody()),
                $result->getEndpoint()
            ]);
        }
    }
}
v4.0.2
  • Fix Subscription::create when not giving every keys
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky