web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.7k stars 295 forks source link

12x performance difference between windows and linux #379

Closed dotthor closed 7 months ago

dotthor commented 10 months ago

Please confirm the following:

Setup

Please provide the following details, the more info you can provide the better.

Please check that you have installed and enabled these PHP extensions :

Please select any browsers that you are experiencing problems with: Please specify the versions (i.e. Chrome Beta, Firefox Beta etc).

Problem

This is my code:

`<?php require_once("vendor/autoload.php"); use Minishlink\WebPush\Subscription; use Minishlink\WebPush\WebPush;

$endpoint = ""; $publicKey = ""; $privateKey = "";

$subscription = Subscription::create(json_decode($endpoint, true)); $auth = [ "VAPID" => [ "subject" => "mailto:me@website.com", // can be a mailto: or your website address "publicKey" => $publicKey, // (recommended) uncompressed public key P-256 encoded in Base64-URL "privateKey" => $privateKey, // (recommended) in fact the secret multiplier of the private key encoded in Base64-URL //"pemFile" => "private_key.pem", // if you have a PEM file and can link to it on your filesystem ], ]; $temp = new StdClass(); $temp->title = "Notifica da PHP"; $temp->body = "Questo testo arriva dal server"; $temp->url = "/";

$payload = json_encode($temp); $webPush = new WebPush($auth); $start_time = microtime(true); $report = $webPush->sendOneNotification($subscription, $payload, ["TTL" => 5000]); $end_time = microtime(true); $elapsed_time = $end_time - $start_time; echo "Tempo trascorso: " . number_format($elapsed_time, 4) . " secondi"; print_r($report->isSuccess() ? "SUCCESS" : "FAILED"); print_r($report->getReason());`

Sending the notification takes 12 seconds on the old windows server, 6 seconds on the new windows server and 0.5 on linux. Is this expected/normal? Is there anything I can do to improve this/am I doing something wrong?

Expected

A gap less big.

Features Used

Example / Reproduce Case

Aformentioned.

Other

Minishlink commented 7 months ago

Hello, performance can be optimized with the extensions bcmath and gmp. Otherwise, most of the work is done by openssl.