PHP Curl Class

Posted on January 10, 2017 at 11:19 pm

Awesome PHP curl class found on github:

$ composer require php-curl-class/php-curl-class &> /dev/null
$ php --interactive
php > require __DIR__ . '/vendor/autoload.php';
php > use \Curl\Curl;
php > $curl = new \Curl\Curl();
php > $curl->setBasicAuthentication('user', 'pass');
php > $curl->get('https://api.github.com/user');
php > echo $curl->httpStatusCode;
200
php > echo $curl->responseHeaders['content-type'];
application/json; charset=utf-8
php > echo $curl->response->login;
php-curl-class
php > echo $curl->rawResponse;
{"login":"php-curl-class","id":7654321,"avatar_url": ...}

https://github.com/php-curl-class/php-curl-class

Make sure to read SECURITY.md for security tips!

Another example calling curl with custom options:

$curl = new Curl();
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
$curl->setOpt(CURLOPT_NOBODY, 1);
$curl->setOpt(CURLOPT_HEADER, 1);
$curl->setUrl('https://httpbin.org/get');
$curl->exec();
var_dump($curl->httpStatusCode);

Updated on March 1, 2017 at 11:48 am

Stay Updated

Other Posts

Updated Posts