github web-push-libs/web-push-php v11.0.0

5 hours ago

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

  • (breaking) feat: use PSR-18 http interface (or http async) by @Minishlink in #458
  • Cast TTL option to string in headers to avoid Guzzle deprecation warnings by @maciek-szn in #456

New Contributors

Full Changelog: v10.1.0...v11.0.0

Don't miss a new web-push-php release

NewReleases is sending notifications on new releases.