Giter VIP home page Giter VIP logo

php7-curl's Introduction

CurlHelper - хелпер для удобной работы с CURL

composer require darkfriend/php7-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
  • 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

php7-curl's People

Contributors

darkfriend avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

spomazanovsky

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.