Search code examples
phpioscurlapple-push-notificationshttp2

How to send an HTTP/2 PING Frame using [PHP] cURL


I am creating a PHP (don't hate!!) script that creates a long-term connection to Apple's new APNS server, as per their new documentation.

The general concept is a while(true) loop that sleeps for n seconds, and checks a queue for outbound push notifications, which are created and inserted into a database by a separate application.

I am getting stuck with comprehending the following section of the documentation, because of my lack of knowledge in the HTTP/2 spec and protocol.

Best Practices for Managing Connections

<snip> You can check the health of your connection using an HTTP/2 PING frame.

As this loop runs, I need to be alerted of the health of my connection, so that I can reconnect, in the case that I get disconnected, or if the connection is somehow terminated.

So, to summarize, how would I send a HTTP/2 PING frame using cURL, specifically, PHP's cURL, and what might the response look like?

I suppose, since cURL uses nghttp2 as the low-level library to interact with HTTP/2, this has something to do with it, but I am not sure how to use nghttp2 functions from within curl: https://nghttp2.org/documentation/nghttp2_submit_ping.html


Solution

  • curl (currently) offers no API that allows an application to send specific HTTP/2 frames like PING.