Home  >  Article  >  Backend Development  >  PHP only sends requests, regardless of how the reply request should be written.

PHP only sends requests, regardless of how the reply request should be written.

WBOY
WBOYOriginal
2016-10-11 14:23:351290browse

I have a small requirement. The program only needs to send requests, and does not care about other things. There is no need to receive return information

Reply content:

I have a small requirement. The program only needs to send requests, and does not care about other things. There is no need to receive return information

Use cURL
cURL can POST some parameters to the specified path. For a specific example, you can parameterize the PHP cURL function

It is easiest to use file_get_contents('http://baidu.com'). If it is more complicated, you can use curl or fsockopen

In fact, what you want is: when sending a request, it does not block your current process

You can start with Baidu PHP asynchronous tasks
Common solutions include Redis publish/subscribe, Gearmand, etc.

My own one is more complicated. PHP uses sockets and Nodejs for high-speed communication (telling nodejs what tasks to perform), and Nodejs serves as the consumer to communicate with RabbitMQ, so I can’t tell you clearly.

The principle is that currently PHP is not responsible for initiating HTTP requests, it is only responsible for notifying what to do and letting a special program perform the request task

<code>do_something();

// 告知后台执行请求任务, 几乎不占用时间就立马执行 next();
do_backend("send_request", "http://www.baidu.com"); 

// 接着做其它东西
next();</code>

Worker side (task execution side, which can be a PHP program or a program in other languages)

<code>// 异步监听任务
subscribe("send_request", function($url){
    file_get_contents($url); // 或 curl
});</code>
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