A parallel HTTP client written in pure PHP
==========================================
This is a powerful HTTP client written in pure PHP code, dose not require any other
PHP extension. It help you easy to send HTTP request and handle its response.
- Process multiple requests in parallel
- Full support for HTTP methods, including GET, POST, HEAD, ...
- Customizable HTTP headers, full support for Cookie, X-Server-Ip
- Follows 301/302 redirect, can set the maximum times
- Supports Keep-Alive, reuse connection to the same host
- Supports HTTPS with openssl
- Allow to upload file via POST method
- Detailed information in DEBUG mode
- Free and open source, release under MIT license
Requirements
-------------
PHP >= 5.4.0
Install
-------
### Install from an Archive File
Extract the archive file downloaded from [httpclient-master.zip](https://github.com/hightman/httpclient/archive/master.zip)
to your project. And then add the library file into your program:
```php
require '/path/to/httpclient.inc.php';
```
### Install via Composer
If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions
at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
You can then install this library using the following command:
~~~
php composer.phar require "hightman/httpclient:*"
~~~
Usage
-------
### Quick to use
We have defined some shortcut methods, they can be used as following:
```php
use hightman\http\Client;
$http = new Client();
// 1. display response contents
echo $http->get('http://www.baidu.com');
echo $http->get('http://www.baidu.com/s', ['wd' => 'php']);
// 2. capture the response object, read the meta information
$res = $http->get('http://www.baidu.com');
print_r($res->getHeader('content-type'));
print_r($res->getCookie(null));
// 3. post request
$res = $http->post('http://www.your.host/', ['field1' => 'value1', 'field2' => 'value2']);
if (!$res->hasError()) {
echo $res->body; // response content
echo $res->status; // response status code
}
// 4. head request
$res = $http->head('http://www.baidu.com');
print_r($res->getHeader(null));
// delete request
$res = $http->delete('http://www.your.host/request/uri');
// 5. restful json requests
// there are sismilar api like: postJson, putJson
$data = $http->getJson('http://www.your.host/request/uri');
print_r($data);
$data = $http->postJson('http://www.your.host/reqeust/uri', ['key1' => 'value1', 'key2' => 'value2']);
```
### Customize request
You can also customize various requests by passing in `Request` object.
```php
use hightman\http\Client;
use hightman\http\Request;
$http = new Client();
$request = new Request('http://www.your.host/request/uri');
// set method
$request->setMethod('POST');
// add headers
$request->setHeader('user-agent', 'test robot');
// specify host ip, this will skip DNS resolver
$request->setHeader('x-server-ip', '1.2.3.4');
// add post fields
$request->addPostField('name', 'value');
$request->addPostFile('upload', '/path/to/file');
$request->addPostFile('upload_virtual', 'virtual.text', 'content of file ...');
// or you can specify request body directly
$request->setBody('request body ...');
// you also can specify JSON data as request body
// this will set content-type header to 'application/json' automatically.
$request->setJsonBody(['key' => 'value']);
// execute the request
$response = $http->exec($request);
print_r($response);
```
### Multiple get in parallel
A great features of this library is that we can execute multiple requests in parallel.
For example, executed three requests simultaneously, the total time spent is one of the longest,
rather than their sum.
```php
use hightman\http\Client;
use hightman\http\Request;
use hightman\http\Response;
// Define callback as function, its signature:
// (callback) (Response $res, Request $req, string|integer $key);
function test_cb($res, $req, $key)
{
echo '[' . $key . '] url: ' . $req->getUrl() . ', ';
echo 'time cost: ' . $res->timeCost . ', size: ' . number_format(strlen($res->body)) . "\n";
}
// or you can define callback as a class implemented interface `ParseInterface`.
class testCb implements \hightman\http\ParseInterface
{
public function parse(Response $res, Request $req, $key)
{
// your code here ...
}
}
// create client object with callback parser
$http = new \hightman\http\Client('test_cb');
// or specify later as following
$http->setParser(new testCb);
// Fetch multiple URLs, it returns after all requests are finished.
// It may be slower for the first time, because of DNS resolover.
$results = $http->mget([
'baidu' => 'http://www.baidu.com/',
'sina' => 'http://news.sina.com.cn/',
'qq' => 'http://www.qq.com/',
]);
// show all results
// print_r($results);
```
> Note: There are other methods like: mhead, mpost, mput ...
> If you need handle multiple different requests, you can pass an array of `Request`
> objects into `Client::exec($reqs)`.
### Export and reused cookies
This library can intelligently manage cookies, default store cookies in memory and send them on need.
We can export all cookies after `Client` object destoried.
```php
$http->setCookiePath('/path/to/file');
```
### Add bearer authorization token
```php
$http->setHeader('authorization', 'Bearer ' . $token);
// or add header for request object
$request->setHeader('authorization', 'Bearer ' . $token);
```
### Enable debug mode
You can turn on debug mode via `Client::debug('open')`.
This will display many debug messages to help you find out problem.
### Others
Because of `Client` class also `use HeaderTrait`, you can use `Client::setHeader()`
to specify global HTTP headers for requests handled by this client object.
Contact me
-----------
If you have any questions, please report on github [issues](https://github.com/hightman/httpclient/issues)
# phpgetext
# phpgetext
没有合适的资源?快使用搜索试试~ 我知道了~
基于php开发的网络爬虫.zip
共122个文件
text:90个
php:20个
gitignore:2个
0 下载量 178 浏览量
2024-08-20
10:49:14
上传
评论
收藏 8.68MB ZIP 举报
温馨提示
项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全栈开发),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助 【资源内容】:项目具体内容可查看/点击本页面下方的*资源详情*,包含完整源码+工程文件+说明(若有)等。【若无VIP,此资源可私信获取】 【本人专注IT领域】:有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为您提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【适合场景】:相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可基于此项目来扩展开发出更多功能 #注 1. 本资源仅用于开源学习和技术交流。不可商用等,一切后果由使用者承担 2. 部分字体及插图等来自网络,若是侵权请联系删除,本人不对所涉及的版权问题或内容负法律责任。收取的费用仅用于整理和收集资料耗费时间的酬劳 3. 积分资源不提供使用问题指导/解答
资源推荐
资源详情
资源评论
收起资源包目录
基于php开发的网络爬虫.zip (122个子文件)
cookie.dat 2KB
cookie.dat.defula 320B
http.php.defulat 5KB
phpunit.xml.dist 1KB
.gitattributes 67B
.gitignore 30B
.gitignore 23B
test.html 418B
composer.json 647B
LICENSE 1KB
README.md 6KB
Processor.php 13KB
Client.php 13KB
Request.php 10KB
ParserDom.php 9KB
HeaderTrait.php 8KB
Connection.php 8KB
demo.php 5KB
http.php 4KB
nuomi.php 4KB
xiangtanmeishi.php 3KB
jiudian.php 3KB
shenghuo.php 3KB
yule.php 3KB
city_id.php 3KB
Response.php 2KB
HtmlTest.php 1KB
test.php 1KB
ParseInterface.php 598B
httpclient.inc.php 573B
bootstrap.php 55B
nuomi_zz_meishi1-622.text 2.28MB
nuomi_hrb_meishi1-421.text 1.4MB
nuomi_ty_meishi1-211.text 1.19MB
nuomi_xa_meishi1-568.text 1.18MB
nuomi_nj_meishi1-224.text 1.17MB
nuomi_ha_meishi1-201.text 1.01MB
nuomi_cq_meishi1-393.text 997KB
nuomi_hz_meishi1-349.text 914KB
nuomi_taizhou_meishi1-250.text 833KB
nuomi_chs_meishi1-167.text 810KB
nuomi_lyg_meishi1-178.text 753KB
nuomi_dg_meishi1-137.text 752KB
nuomi_fs_meishi1-85.text 747KB
nuomi_nn_meishi1-123.text 745KB
nuomi_qd_meishi1-289.text 734KB
nuomi_xj_meishi1-96.text 671KB
nuomi_luoyang_meishi1-111.text 645KB
nuomi_haikou_meishi1-101.text 633KB
nuomi_qz_meishi1-48.text 615KB
nuomi_cc_meishi1-183.text 607KB
nuomi_xz_meishi1-126.text 599KB
nuomi_bd_meishi1-122.text 581KB
nuomi_ay_meishi1-61.text 575KB
nuomi_lz_meishi1-136.text 548KB
nuomi_sh_meishi1-20.text 546KB
nuomi_wuhu_meishi1-55.text 543KB
nuomi_jj_meishi1-69.text 538KB
nuomi_gl_meishi1-68.text 538KB
nuomi_lc_meishi1-48.text 536KB
nuomi_zj_meishi1-75.text 532KB
nuomi_liuzhou_meishi1-62.text 516KB
nuomi_tj_meishi1-243.text 512KB
nuomi_jn_meishi1-289.text 501KB
nuomi_dq_meishi1-46.text 500KB
nuomi_gy_meishi1-69.text 488KB
nuomi_wz_meishi1-163.text 485KB
nuomi_nt_meishi1-141.text 481KB
nuomi_huizhou_meishi1-39.text 473KB
nuomi_baoji_meishi1-74.text 451KB
nuomi_fz_meishi1-259.text 434KB
nuomi_yz_meishi1-164.text 434KB
nuomi_dl_meishi1-169.text 414KB
nuomi_ny_meishi1-38.text 410KB
nuomi_xx_meishi1-76.text 402KB
nuomi_sjz_meishi1-220.text 402KB
nuomi_ts_meishi1-97.text 387KB
nuomi_sy_meishi1-243.text 378KB
nuomi_nd_meishi1-54.text 364KB
nuomi_sx_meishi1-44.text 352KB
nuomi_zhangzhou_meishi1-56.text 345KB
nuomi_zaozhuang_meishi1-44.text 344KB
nuomi_pds_meishi1-56.text 343KB
nuomi_zh_meishi21-48.text 314KB
nuomi_hu_meishi1-24.text 309KB
nuomi_zh_meishi1-20.text 304KB
nuomi_jm_meishi1-30.text 284KB
nuomi_xm_meishi1-290.text 272KB
nuomi_sh_meishi21-40.text 250KB
nuomi_zhanjiang_meishi1-48.text 241KB
nuomi_sh_meishi41-60.text 240KB
nuomi_bt_meishi1-20.text 230KB
nuomi_km_meishi1-83.text 219KB
nuomi_lf_meishi1-86.text 217KB
nuomi_tz_meishi1-23.text 217KB
nuomi_bj_jiudian0-20.text 216KB
nuomi_sh_meishi141-160.text 213KB
nuomi_sh_meishi101-120.text 206KB
nuomi_zhuzhou_meishi1-40.text 202KB
nuomi_yancheng_meishi1-124.text 196KB
共 122 条
- 1
- 2
资源评论
热爱技术。
- 粉丝: 2622
- 资源: 7860
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于STM32F103C8T6的车辆落水报警系统源码+文档说明+原理图(毕业设计)
- 学之思开源考试系统是一款java+vue的前后端分离的考试系统 主要优点是开发、部署简单快捷、界面设计友好、代码结构清晰 支持web端和微信小程序,能覆盖到pc机和手机等设备 支持多种部署方式
- PHP旅游智能CRM系统源码数据库 MySQL源码类型 WebForm
- 大数据1+x(蓝桥课堂实操231216)解析
- 基于STM32F103C8T6的双轮平衡小车项目源码(代码注释全面适合小白)
- 金杰.m4a..mp3
- PHP出租屋租赁系统源码带小程序数据库 MySQL源码类型 WebForm
- Matlab实例:频谱、功率谱和功率谱密度计算作业
- 企业级免费开源商城系统,可视化DIY拖拽装修、包含PC、H5、多端小程序(微信+支付宝+百度+头条&抖音+QQ+快手)、APP、多仓库、多商户、多门店、IM客服、进销存,遵循MIT开源协议发布
- 毕业设计基于STM32F103C8T6的智能宠物屋系统源码+文档说明+原理图
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功