基于上次写的关于php的libevent扩展的应用,我实现了一个异步的http请求类。
代码在github上:https://github.com/volca/AsyncHttpClient
使用示例
如下,在request的时候能够定义请求完成之后的callback函数。
$base
);
for($i = 0; $i < 10; $i++) {
$client = new AsyncHttpClient($uri, $config);
$client->request(function($result) {
echo "Result len:";
echo strlen($result[\'response\']);
echo "n";
});
}
event_base_loop($base);
echo "donen";
目前的实现比较初级,只做了get方法的封装,如果需要http上传或者post,还需要另外实现。另外这个类也需要php的libevent扩展。