Home > php教程 > php手册 > body text

php的异步http请求类

WBOY
Release: 2016-06-21 08:52:48
Original
951 people have browsed it

  使用示例

  如下,在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扩展。



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!