Home >php教程 >php手册 >php的异步http请求类

php的异步http请求类

WBOY
WBOYOriginal
2016-06-21 08:52:481002browse

  使用示例

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



Statement:
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
Previous article:php操作SVN类Next article:GBK编码PHP脚本导致语法错误