darkfriend / php7-curl
There is no license information available for the latest version (1.0.5) of this package.
PHP7 curl helper
1.0.5
2021-04-15 21:12 UTC
Requires
- php: >=7.0
- darkfriend/php7-array: *
- darkfriend/php7-debug: *
- darkfriend/php7-string: *
- darkfriend/php7-xml: ^1.0
README
composer require darkfriend/php7-curl
CurlHelper::getInstance($newSession = false, $options = [])
- return instance CurlHelperCurlHelper::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
- head
- 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