2017 © Pedro Peláez
 

library php-coroutine-http-client

php coroutine http client

image

lanzhi/php-coroutine-http-client

php coroutine http client

  • Thursday, May 3, 2018
  • by lanzhi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

协程 HTTP 客户端

简介

提供可以在协程模式下工作的非阻塞 HTTP 请求功能。
当前根据项目实际需要,仅提供最小化功能。, (*1)

具体功能如下:

  1. 只支持 GET、POST 请求;
  2. 不支持文件上传;
  3. 不支持 HTTPS 协议;
  4. 不支持 gzip、deflate 等内容编码;
  5. 不支持 COOKIE;
  6. 不支持认证机制;

使用方式:

API 参照 guzzlehttp 设计,不过不支持其中部分选项。
Example 1:, (*2)

include __DIR__."/../vendor/autoload.php";

use lanzhi\http\Client;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Logger\ConsoleLogger;

$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_VERY_VERBOSE);
$client = new Client([], new ConsoleLogger($output));

//file:get.php 将拿到的 $_GET 参数 ksort 排序之后,使用 json_encode($get, JSON_UNESCAPED_UNICODE) 转换为字符串输出
$uri = "test.com/get.php";
$query = [
    'name' => 'lanzhi',
    'sex'  => 'male',
    'age'  => 'unknown',
    'tag'  => uniqid()
];

$request = $client->get($uri, ['query'=>$query]);
$request->run();
$response = $request->getReturn();
if($response->getBody()){
    echo "response body size:", $response->getBody()->getSize(), "\n";
    ksort($query);
    echo "query: ", json_encode($query, JSON_UNESCAPED_UNICODE), "\n";
    echo "body:  ", $response->getBody()->getContents(), "\n";
}else{
    var_dump($response);
}

echo "response status: ", $response->getStatusCode(), "\n";
echo "response phrase: ", $response->getReasonPhrase(), "\n\n";


其它可参见项目 examples 目录, (*3)

联系作者

QQ : 310929334
微信: lanzhi_me, (*4)

The Versions

03/05 2018

dev-master

9999999-dev

php coroutine http client

  Sources   Download

MIT

The Requires

 

The Development Requires

by 蓝至

php http client http client coroutine

03/05 2018

0.1

0.1.0.0

php coroutine http client

  Sources   Download

MIT

The Requires

 

The Development Requires

by 蓝至

php http client http client coroutine

03/05 2018

v0.0.5

0.0.5.0

php coroutine http client

  Sources   Download

MIT

The Requires

 

The Development Requires

by 蓝至

php http client http client coroutine