"PHP Fatal error: Class 'HttpRequest' not found"

"PHP Fatal error: Class 'HttpRequest' not found"

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

Stefan Bogdanescu

Founder & Senior Architect

PHP Fatal error: Class 'HttpRequest' not found

You are encountering a classic namespace collision between the legacy pecl_http extension and modern PHP core libraries. The error PHP Fatal error: Class 'HttpRequest' not found usually implies one of two things: either the extension isn't loaded at all, or the code you are writing is using an outdated API that has been superseded by the standard library in your current PHP version.

The source material describes a developer working on Mac OS X 10.7 with MAMP, attempting to use new HttpRequest('something'). This specific class belongs to the pecl_http package (specifically the legacy C extension), not the modern ext/http provided in PHP 5.3 and later, nor the ubiquitous ext/sockets or ext/fileinfo often confused with it.

Why the Class Is Missing

When you run pecl install pecl_http, you are installing a specific C extension that defines the HttpRequest class. However, many developers fail to realize that simply installing the PECL module does not automatically enable the corresponding line in php.ini. The source material mentions adding extension=http.so to the configuration file.

If this line is missing or commented out, PHP will load your application code but never instantiate the extension's classes. Consequently, when you call new HttpRequest(), PHP looks for the class definition in its internal symbol table, finds nothing, and throws the fatal error.

To verify if the extension is loaded, check your active configuration file (often located at /Applications/MAMP/bin/php/php5.5.3/conf/php.ini). Look for the line:

extension=http.so

If it is missing, add it. If it exists but is prefixed with a semicolon (;), remove the semicolon. After modifying the file, you must restart the MAMP server to apply the changes.

The Legacy vs. Modern API Trap

Even if you successfully load the http.so extension and the HttpRequest class becomes available, the code snippet provided in the source material is technically obsolete for modern PHP development.

The HttpRequest class from pecl_http was designed for synchronous HTTP requests where you construct an object, set headers manually, and execute it. While this works on older setups, it is generally discouraged today because it blocks script execution while waiting for the response. Furthermore, the namespace has shifted. In modern PHP contexts (PHP 5.4+), the preferred way to handle HTTP requests without external dependencies is using the native GuzzleHttp library or cURL directly.

If you are maintaining legacy code that strictly requires the HttpRequest class, ensure you are not accidentally mixing namespaces. The error message suggests PHP simply cannot find the definition. This often happens if:

  1. The extension is built but not loaded (checked via php -m).
  2. You are using a PHP version where pecl_http was deprecated or removed from standard distributions, and you accidentally installed an incompatible build.

Troubleshooting Steps

If adding the line to php.ini does not resolve the issue, follow these steps:

  1. Verify Module Loading: Run the following command in your terminal (ensure your MAMP PHP bin is in your PATH):

    /Applications/MAMP/bin/php/php5.5.3/bin/php -m | grep http
    

    If http does not appear in the list, the extension is not active despite being installed.

  2. Check for Conflicts: Sometimes, multiple versions of extensions with similar names exist. Ensure you aren't loading an older version of the HTTP extension that conflicts with the new one. The source material mentions adding extension=raphf.so and extension=propro.so. These are unrelated to HTTP requests. Focus solely on ensuring http.so is present and enabled.

  3. Restart Services: As noted in the source material, restarting MAMP is mandatory after changing php.ini. However, ensure you restart both the Apache/Nginx server and the PHP-FPM service if using it, as they often read configuration from different sources or require a full service reload.

Modern Alternatives

If your goal is simply to make an HTTP GET request in a WordPress plugin or similar environment, consider switching to cURL or a dedicated library like Guzzle. This avoids the dependency on PECL extensions entirely.

Here is a robust alternative using cURL that does not rely on the HttpRequest class:

$ch = curl_init('https://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
$response = curl_exec($ch);
curl_close($ch);

This approach is more portable across different PHP versions and server configurations. If you must stick with the HttpRequest class for legacy reasons, ensure your environment matches the exact requirements listed in the PECL documentation for that specific version, rather than guessing based on online guides which often become outdated.

Our network