pulkitjalan/requester
最新稳定版本:1.1.0
Composer 安装命令:
composer require pulkitjalan/requester
包简介
Requester class to wrap guzzle and retry subscriber
README 文档
README
Simple Requester class to wrap guzzle and the retry subscriber
This package requires PHP >=5.4
Installation
Install via composer - edit your composer.json to require the package.
"require": { "pulkitjalan/requester": "2.*" }
Then run composer update in your terminal to pull it in.
Laravel 5
There is a Laravel 5 service provider and facade available.
Add the following to the providers array in your config/app.php
'PulkitJalan\Requester\RequesterServiceProvider'
Next add the following to the aliases array in your config/app.php
'Requester' => 'PulkitJalan\Requester\Facades\Requester'
Next run php artisan vendor:publish --provider="pulkitjalan\requester\RequesterServiceProvider" --tag="config" to publish the config file.
Looking for a Laravel 4 compatible version?
Checkout the 1.0 branch
Usage
The requester class has a dependency of guzzle and takes in an instance of guzzle as the first param.
This package also uses a few guzzle subscribers. https://github.com/guzzle/retry-subscriber for retry functionality and https://github.com/guzzle/log-subscriber for logging.
Available request methods: get, head, delete, put, patch, post, options
<?php use PulkitJalan\Requester\Requester; use GuzzleHttp\Client as GuzzleClient; $requester = new Requester(new GuzzleClient()); // simple get request $requester->url('example.com')->get();
Altering the default retry behaviour. See retry-subscriber for more info.
// retry 10 times, with a 1 second wait on a 503 error $requester->url('example.com')->retry(10)->every(1000)->on([503])->get(); // disabling retry $requester->url('example.com')->retry(false)->get();
Disabling ssl check
// ssl check disabled $requester->url('example.com')->verify(false)->get();
Use http instead of https
// disable https and use http $requester->url('example.com')->secure(false)->get(); // use http $requester->url('http://example.com')->get();
Create a Post request
// Create a post request $requester->url('example.com/update/1')->post([ 'body' => [ 'title' => 'some title' ] ]); // Upload a file $requester->url('example.com/upload')->addFile('/tmp/image.jpg')->post([ 'body' => [ 'title' => 'Some image', 'description' => 'Some image description' ] ]);
Guzzle 5 uses RingPHP and has the added functionality of performing request asynchronously.
Performing asynchronous requests
// Create a post request $response = $requester->url('example.com')->async(true)->get(); // Use the response asynchronously $this->response = $response->then(function ($response) { return $response->getBody(); }); // Use the response synchronously $this->response = $response->getBody();
Logging guzzle requests to file. See log-subscriber for more info.
use PulkitJalan\Requester\Requester; use GuzzleHttp\Client as GuzzleClient; use Monolog\Logger; use Monolog\Handler\StreamHandler; // create a log channel $log = new Logger('name'); $log->pushHandler(new StreamHandler('/path/to/your.log', Logger::INFO)); $requester = new Requester(new GuzzleClient()); $requester->addLogger($log); // request and response logged to file $requester->url('example.com')->get(); // Use the second param to update the format $requester = new Requester(new GuzzleClient()); $requester->addLogger($log, 'DEBUG');
pulkitjalan/requester 适用场景与选型建议
pulkitjalan/requester 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31.43k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2014 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「curl」 「http」 「Guzzle」 「retry」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pulkitjalan/requester 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pulkitjalan/requester 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pulkitjalan/requester 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
repository php library
Simple cURL wrapper
A fluent PHP CURL wrapper
Cloudflare Middleware For Guzzle
Simplifies working with holaluz API endpoints
统计信息
- 总下载量: 31.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-12