Skip to content
A simple PHP HTTP request class.
Branch: 1.x
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
JJG Add timeout and connectTimeout getters and setters. Sep 23, 2014
Resources Added Request library, MIT License, and Logo. Sep 10, 2013 Updated URL for Request logo. Jun 24, 2014
composer.json Updated composer.json with correct namespace. Oct 10, 2013

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:


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

You can’t perform that action at this time.