PHP Reuse a HTTP 2 curl connection

Viewed 126

I built a small php utility that sends a few push-notification (around 15k) to apple devices.

    curl_setopt($http2ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
    curl_setopt($http2ch, CURLOPT_PORT, 443);
    curl_setopt($http2ch, CURLOPT_HTTPHEADER, $httpHeader);
    curl_setopt($http2ch, CURLOPT_POST, true);
    curl_setopt($http2ch, CURLOPT_POSTFIELDS, $body);
    curl_setopt($http2ch, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($http2ch, CURLOPT_TIMEOUT, 30);

    foreach ($deviceIds as $deviceId) {
        $url ="https://api.push.apple.com/3/device/" . $deviceId;
        curl_setopt($http2ch, CURLOPT_URL, $url);
        curl_exec($http2ch);
    }

    curl_close($http2ch);

It opens up a HTTP2 connection to the apple push-notification endpoint and loops trough the deviceIds to send each message. That works so far, but it is rather slow. Using this solution I can send around 10 messages/sec which seems very slow to me.

Is this the proper way to reuse an open http2 connection or do I do something wrong?

0 Answers
Related