dHttp is a lightweight library to work with PHP Curl. Easy-to-use library!
- Using packagist/composer: The recommended way to install library is through composer.
{
"require": {
"aracoool/dhttp" : "~2.0"
}
}
- Cloning the git repository
dHttp (php curl library) works with PHP 7.3 7.4
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'));
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',
));
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());
}
\dHttp\Client::v();