Skip to content
/ dHttp Public

dHttp (php curl library) makes it easy to send HTTP requests and integrate with web APIs

Notifications You must be signed in to change notification settings

ARACOOOL/dHttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dHttp is a lightweight library to work with PHP Curl. Easy-to-use library!

Latest Stable Version Build Status Scrutinizer Code Quality License

SensioLabsInsight

Install

  • Using packagist/composer: The recommended way to install library is through composer.
{
    "require": {
        "aracoool/dhttp" : "~2.0"
    }
}
  • Cloning the git repository

Requirements

dHttp (php curl library) works with PHP 7.3 7.4

Usage

GET request:

required __DIR__ . '/vendor/autoload.php';

// http://website.com?param1=value1
$client = new dHttp\Client(['http://website.com', [
    'param1' => 'value1'
]], [CURLOPT_TIMEOUT => 5]);

$resp = $client->get();
// Get response code
var_dump($resp->getCode());
// Get response body
var_dump($resp->getBody());
// Get request errors
var_dump($resp->getErrors());
// Return response headers
var_dump($resp->getHeaders());
// Return a specific (text/html; charset=utf-8)
var_dump($resp->getHeader('Content-Type'));

POST request:

required __DIR__ . '/vendor/autoload.php';

$client = new dHttp\Client('http://website.com');
$client->addOptions([CURLOPT_RETURNTRANSFER => false])
	->setCookie('/tmp/cookie.txt')
	->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31')
	->post(array(
		'field1' => 'value1',
		'field2' => 'value2',
));

Multithreaded query:

required __DIR__ . '/vendor/autoload.php';

$client = new dHttp\Client();
$response_array = $client->multi(array(
	new dHttp\Client('http://website1.com'),
	new dHttp\Client('http://website2.com', array(
		CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1',
		CURLOPT_TIMEOUT => 5,
	))
));

foreach($response_array as $item) {
	var_dump($item->getCode());
}

Get cURL version:

\dHttp\Client::v();

About

dHttp (php curl library) makes it easy to send HTTP requests and integrate with web APIs

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages