php的异步http请求类
Jun 21, 2016 am 08:52 AM使用示例
如下,在request的时候能够定义请求完成之后的callback函数。
$base = event_base_new();
$uri = "http://www.baidu.com/";
$config = array(
'eventbase' => $base
);
for($i = 0; $i
$client = new AsyncHttpClient($uri, $config);
$client->request(function($result) {
echo "Result len:";
echo strlen($result['response']);
// parse response with Zend_Http_Response
$response = Zend_Http_Response::fromString($result['response']);
echo $response->getBody();
echo "\n";
});
}
event_base_loop($base);
echo "done\n";
?>
目前的实现比较初级,只做了get方法的封装,如果需要http上传或者post,还需要另外实现。另外这个类也需要php的libevent扩展。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Use regular expressions in golang to verify whether the input is a legal base64 string

How to encode and decode using Base64 functions in Java

Laravel Development: How to return a response using Laravel Response?

Five selected Go language open source projects to take you to explore the technology world

Go language development essentials: 5 popular framework recommendations

Implementing distributed task scheduling using Golang's web framework Echo framework
