Giter Club home page Giter Club logo

multihttp's Introduction

MultiHttp

This is high performance PHP curl wrapper written in PHP.
It's compatible with PHP 5.4+ and HHVM .

Contents

Feature

  • alias of curl option, e.g. 'timeout' equals 'CURLOPT_TIMEOUT' etc.
  • Request and MultiRequest class , can be used in any combination
  • graceful and efficient

Installation

You can use composer to install this library from the command line.

composer require sinacms/multihttp

Usage

Single-request:

<?php
// Include Composer's autoload file if not already included.
require __DIR__.'/vendor/autoload.php';
use MultiHttp\Request;
use MultiHttp\Response;


$responses=array();
$responses[] = Request::create()->addQuery('wd=good')->get('http://baidu.com?', array(
          'timeout' => 3,
          'timeout_ms' => 2000,
          'callback' => function (Response $response) {

          }))->execute();

$responses[] = Request::create()->get('http://qq.com', array(
          'callback' => function (Response $response) {
              //sth
          }))->addOptions(array(
          'method' => Request::PATCH,
          'timeout' => 3,
      ))->execute();
      //test post
$responses[] = Request::create()->post(
      'http://127.0.0.1',array('data'=>'this_is_post_data'), array(
          'callback' => function (Response $response) {
              //sth
          }))->execute();

foreach ($responses as $response) {
  echo $response->request->getURI(), ' takes:', $response->duration,  "\n\t\n\t";
}
?>

Multi-request:

<?php
use MultiHttp\MultiRequest;

$mr  = MultiRequest::create();
$rtn = $mr->addOptions(
    array(
        array(
            'url'    => 'http://google.com',
            'timeout' => 2,
            'method' => 'HEAD',
            'data'   => array(
            ),
            'callback' => function (Response $response) {
                //sth
            }
        ),
    ))
    ->add('GET', 'http://sina.cn',array(), array(
        'timeout' => 3
    ))
    ->import(Request::create()->trace('http://sohu.cn', array(
            'timeout'  => 3,
            'callback' => function (Response $response) {
                //sth
            }))->applyOptions())
	->execute();
    foreach ($rtn as $response) {
        echo $response->request->getURI(), ' takes:', $response->duration, ' ', "\n\t\n\t";
    }

?>

Documentation

  • Request

  • public static function create()
  • public function endCallback()
  • public function hasEndCallback()
  • public function onEnd(callable$callback)
  • public function getURI()
  • public function getIni($field)
  • public function addQuery($data)
  • public function post($uri, array $payload = array(), array $options = array())
  • public function addOptions(array $options = array())
  • public function get($uri, array $options = array())
  • public function execute()
  • public function applyOptions()
  • public function makeResponse($isMultiCurl = false)
  • MultiRequest

  • public static function create()
  • public function addOptions(array $URLOptions)
  • public function add($method, $uri, array $payload = array(), array $options = array())
  • public function import(Request $request)
  • public function execute()

multihttp's People

Watchers

 avatar  avatar

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.