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
Requires
- php: >=5.4
- darkfriend/php5-array: ^1.0
- darkfriend/php5-debug: ^1.0
- darkfriend/php5-string: ^1.0
- darkfriend/php5-xml: ^1.0
README
composer require darkfriend/php5-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
- 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