web-push-php icon indicating copy to clipboard operation
web-push-php copied to clipboard

From one and a half minutes to one hour to send

Open chelssi opened this issue 1 year ago • 2 comments

Setup

  • Operating System: Linux
  • PHP Version: 8.1
  • web-push-php Version: 8.0

PHP extensions :

  • [x] curl
  • [x] gmp
  • [x] mbstring
  • [x] openssl

browsers:

  • [x] Chrome
  • [x] Firefox
  • [x] Firefox for Mobile
  • [x] Opera for Android
  • [x] Samsung Internet Browser
  • [x] Other

I was using version 6, and 44,000 endpoints were being sent in 1m 40s. After updating to version 8, the time has increased to almost 1 hour, and I don’t know what could be the reason.

This is the portion of sending code

$defaultOptions = [
    'TTL' => 300, // defaults (300) to 4 weeks
    'urgency' => 'normal', // protocol defaults to "normal"
    'topic' => 'new_event', // not defined by default,
    'batchSize' => 1000, // defaults to 1000
    'verify' => false,
    'timeout' => 6, // defaults to 20 
    '\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS' => false
];

$webPush = new WebPush([], $defaultOptions);
$webPush->setAutomaticPadding(true);
$auth = array(
        'VAPID' => array(
            'subject' => 'https://www.mydomain.com',
            'publicKey' => file_get_contents(__DIR__ . '/../../../../keys/public_key.txt'),
            'privateKey' => file_get_contents(__DIR__ . '/../../../../keys/private_key.txt'),
        ),
    );
$webPush = new WebPush($auth);
$i = 0;
$notifications = [];
while ($row_subscription = $result -> fetch_assoc()){
    $i ++;
	$subscription_id = $row_subscription['subscription_id'];
        $payload = [
            "title" => $row_notificacion['title'],
            "body" => $row_notificacion['body'],
            "badge" => $row_notificacion['badge'],
            "icon" => $row_notificacion['icon'],
            "image" => $row_notificacion['image'],
            "url" => $row_notificacion['url'],
            "id" => $notification_id,
            "sid" => $subscription_id,
            "requireInteraction" => true,
            "vibrate" => "[300, 100, 400]"
        ];
    $data = json_encode($row_subscription);
    $subscription = Subscription::create(json_decode($data, true));
    $notifications[] = [
        'subscription' => $subscription,
        'payload' => json_encode($payload),
    ];
    if ($i % 1000 == 0 || $result->num_rows == $i) {
        foreach ($notifications as $notification) {
            $webPush->queueNotification($notification['subscription'], $notification['payload']);
        }

        foreach ($webPush->flush() as $report) {
            handleReport();
        }
        $notifications = [];
        
    }
}

Thank you

chelssi avatar Jul 20 '24 17:07 chelssi

Hello, thanks for the report. Was the web-push-php upgrade the only change that you made? (no new PHP version, no changes in PHP extensions...)

Minishlink avatar Jul 30 '24 12:07 Minishlink

Hi,

No change, in fact I've come back again to V6 with the same settings of php and extensions and again we are sending 44,000 pushes in less than two minutes.

I don't know where can be the problem.

thank you for you help.

chelssi avatar Jul 30 '24 15:07 chelssi