Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darkfriend/php5-curl
https://github.com/darkfriend/php5-curl
curl helper php php5 request
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/darkfriend/php5-curl
- Owner: darkfriend
- Created: 2019-12-20T19:41:43.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-15T21:13:20.000Z (almost 4 years ago)
- Last Synced: 2024-03-14T15:46:20.615Z (11 months ago)
- Topics: curl, helper, php, php5, request
- Language: PHP
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CurlHelper - хелпер для удобной работы с CURL
``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
```php
$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
```php
$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
```php
$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
```