darkfriend / php5-curl
PHP5 curl helper
Installs: 2 317
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
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