A simple PHP HTTP request class.

1.x-dev 2021-12-15 19:06 UTC

This package is auto-updated.

Last update: 2024-06-16 00:25:15 UTC


Request for PHP Logo


A simple PHP HTTP request class.

This class includes many convenience methods to help take the headache out of dealing with HTTP requests in PHP.


Include the class (\JJG\Request) using an autoloader, then build a new Request object, execute the request, and get the response.

$request = new Request('');
$response = $request->getResponse();

Other parameters you can retrieve after executing a request include:

// The full headers from the response.
// The latency for this response, in ms.
// The HTTP status code (e.g. 200 for 200 OK).
// Empty if no error present, otherwise shows any cURL errors.

There are also other convenient methods included for other purposes.

// Returns TRUE if 'string' exists in the response.

You can also make requests with basic HTTP authentication:

// Execute a request with HTTP basic authentication.
$request = new Request('');
$request->setBasicAuthCredentials('username', 'password');

Other options include enabling or disabling SSL, using cookies, and setting cURL timeout values:

// Enable Cookies.
// Enable SSL/TLS.
// Set the user agent string.
$request->userAgent = 'User agent string here.';
// Set the initial connection timeout (default is 10 seconds).
$request->connectTimeout = 5;
// Set the timeout (default is 15 seconds).
$request->timeout = 10;
// Send some fields as a POST request.

See the Request class variable definitions and methods for more details and documentation.

Why Request?

I've used other HTTP request libraries for PHP before, but often fall back to using cURL directly, because the libraries I've used are too complicated for my needs. This library aims to be a very simple and easy-to-use wrapper around cURL, and should be easy to pick up for anyone familiar with cURL usage in PHP.

Some other recommended HTTP libraries for PHP include:


Request is licensed under the MIT (Expat) license. See included