PHP Curl - Received HTTP/0.9 when not allowed

PHP Curl - Received HTTP/0.9 when not allowed

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

PHP Curl - Received HTTP/0.9 when not allowed

When attempting to send a POST request to Apple's Push Notification service using PHP, developers often encounter a specific error that defies immediate intuition: Curl failed: Received HTTP/0.9 when not allowed. This occurs even when the code explicitly configures CURLOPT_HTTP_VERSION to CURL_HTTP_VERSION_2_0.

The discrepancy between your configuration and the actual protocol used is not a bug in PHP or cURL itself, but a fundamental limitation of how the underlying curl library interacts with certain remote servers. To understand why this happens, we must look past the high-level API settings and examine the TLS handshake process.

The Protocol Negotiation Failure

The error message "Received HTTP/0.9 when not allowed" is technically accurate regarding what the server responded with, but it masks the root cause: a failed negotiation for HTTP/2.0.

HTTP/2.0 support relies on ALPN (Application-Layer Protocol Negotiation) during the TLS handshake. When your PHP script initiates curl_init() and sets CURLOPT_HTTP_VERSION to 2, cURL attempts to negotiate an HTTP/2 connection with the remote server via the ALPN extension in the TLS handshake.

Apple's Push Notification service (api.push.apple.com) has historically supported both HTTP/1.1 and HTTP/2. However, depending on the specific configuration of the cURL binary bundled with your PHP distribution (specifically version 7.66.0 as mentioned in the source scenario), the library may fail to successfully negotiate ALPN if the server does not explicitly advertise HTTP/2 support or if the negotiation times out.

When the ALPN negotiation fails, the cURL library falls back to its default behavior: initiating a standard HTTP/1.1 request. If the remote server is configured to strictly require HTTP/2 and rejects the fallback attempt, it may send a response formatted in an outdated protocol version (HTTP/0.9) or simply close the connection, causing cURL to throw this specific exception.

Diagnosing the Root Cause

To confirm whether the issue lies with your client configuration or the server's ability to negotiate protocols, you can inspect the TLS handshake details directly from the command line before integrating them into your application.

First, ensure that your system's curl binary actually supports HTTP/2. Run the following command in your terminal:

curl --version | grep "HTTP2"

If this returns nothing, your system lacks HTTP/2 support regardless of your PHP settings. You may need to install a newer version of libcurl or update the package manager repositories.

Next, verify if the remote server is willing to negotiate HTTP/2. Use the --http2 flag combined with verbose output:

curl --version --http2 -v https://api.push.apple.com/3/device/test

Observe the ALPN line in the verbose output. If it shows h2, the negotiation succeeded. If it shows h2,h1 or nothing, the server is not offering HTTP/2 in a way your client can accept.

Implementing a Robust Solution

If you cannot upgrade the cURL library or if the specific endpoint requires strict HTTP/2 support that your current environment cannot provide, relying solely on CURLOPT_HTTP_VERSION is insufficient. You must handle the fallback gracefully.

The most reliable approach is to attempt the request with HTTP/1.1 by default, as this is universally supported and often sufficient for sending push notifications to Apple unless specific binary payload constraints exist. If you strictly require HTTP/2 (for multiplexing or header compression), you must ensure your environment supports ALPN negotiation correctly.

Here is an adjusted implementation that explicitly sets the version but also prepares for the failure mode:

$http2ch = curl_init();

// Explicitly request HTTP/2, but be aware of server-side ALPN support
curl_setopt($http2ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($http2ch, CURLOPT_URL, 'https://api.push.apple.com/3/device/megauniquedevicetokendummy');
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, true);
curl_setopt($http2ch, CURLOPT_TIMEOUT, 30);
curl_setopt($http2ch, CURLOPT_HEADER, 1);

$result = curl_exec($http2ch);

if ($result === false) {
    $error = curl_error($http2ch);
    $code = curl_getinfo($http2ch, CURLINFO_HTTP_CODE);
    
    // Check specifically for the ALPN negotiation failure
    if (strpos($error, 'Received HTTP/0.9 when not allowed') !== false) {
        // The server rejected the fallback or the handshake failed.
        // Consider falling back to HTTP/1.1 logic here if business rules permit.
        throw new \Exception("Curl failed: " . $error . " | Code: " . $code);
    }
    
    throw new \Exception("Curl failed: " . $error . " | " . $code);
}

In production environments, the trade-off often favors reliability over strict protocol adherence. If your application logic does not strictly require HTTP/2 features like stream multiplexing, falling back to CURLOPT_HTTP_VERSION set to CURL_HTTP_VERSION_1_1 (or omitting the setting entirely) resolves this issue immediately. The error "Received HTTP/0.9 when not allowed" is effectively a signal that the server refused the connection because it could not agree on the transport layer protocol, not necessarily because your HTTP version flag was wrong.

Conclusion

The Received HTTP/0.9 when not allowed error is a manifestation of an ALPN handshake failure during the TLS negotiation phase. It occurs when the cURL library attempts to use HTTP/2, fails to negotiate it with the remote server, and receives a rejection that looks like an ancient protocol version. The solution involves verifying your system's libcurl support for HTTP/2 or adjusting your application logic to accept HTTP/1.1 as a fallback if strict HTTP/2 compliance is not a hard requirement for your specific use case.

Our network