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

php的异步http请求类

Jun 21, 2016 am 08:52 AM
base echo quot response

  使用示例

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Base DEX Faucet: Aerodrome VS Curve Base DEX Faucet: Aerodrome VS Curve Mar 26, 2024 pm 04:31 PM

Base DEX Faucet: Aerodrome VS Curve

Use regular expressions in golang to verify whether the input is a legal base64 string Use regular expressions in golang to verify whether the input is a legal base64 string Jun 24, 2023 am 10:01 AM

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 How to encode and decode using Base64 functions in Java Jun 26, 2023 pm 02:24 PM

How to encode and decode using Base64 functions in Java

Laravel Development: How to return a response using Laravel Response? Laravel Development: How to return a response using Laravel Response? Jun 14, 2023 am 10:39 AM

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 Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

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

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

Go language development essentials: 5 popular framework recommendations

Implementing distributed task scheduling using Golang's web framework Echo framework Implementing distributed task scheduling using Golang's web framework Echo framework Jun 24, 2023 am 11:49 AM

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

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决

See all articles