darkfriend/php5-curl

There is no license information available for the latest version (1.0.6) of this package.

PHP5 curl helper

1.0.6 2021-04-15 21:12 UTC

This package is auto-updated.

Last update: 2024-05-16 03:47:28 UTC


README

composer require darkfriend/php5-curl

  • CurlHelper::getInstance($newSession = false, $options = []) - return instance CurlHelper
  • CurlHelper::getInstance($newSession = false, $options = [])->request($url, $data = [], $method = 'post', $requestType = '', $responseType = 'json') - do request to url

Support request method type

  • post
  • get
  • put
  • delete
  • options
  • custom

Support request type

  • json
  • xml
  • custom

Support response type

  • json
  • xml
  • custom

Example1

$url = 'http://site.ru';
$curl = \darkfriend\helpers\CurlHelper::getInstance();
$response = $curl->request($url);

// $response - array response site.ru
// $curl->lastCode - response http code
// $curl->lastHeaders - response http headers

Example2: CurlHelper with custom headers

$url = 'http://site.ru';
$curl = \darkfriend\helpers\CurlHelper::getInstance();
$response = $curl->setHeaders([
            'Accept-Language' => 'ru-RU',
            'Custom-Head' => 'custom',
        ])
        ->request($url);

// $response - array response site.ru
// $curl->lastCode - response http code
// $curl->lastHeaders - response http headers

Example3: CurlHelper with debug

$url = 'http://site.ru';
$curl = \darkfriend\helpers\CurlHelper::getInstance(false,[
    'debug' => true,
    'debugFile' => __DIR__.'/logs'
]);
$response = $curl->request($url);

// $response - array response site.ru
// $curl->lastCode - response http code
// $curl->lastHeaders - response http headers