PHP 多卷曲请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3900153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:25:19  来源:igfitidea点击:

PHP Multiple Curl Requests

phpcurlcurl-multi

提问by Simon

I'm currently using Curl for PHP a lot. It takes a lot of time to get results of about 100 pages each time. For every request i'm using code like this

我目前在 PHP 中使用 Curl 很多。每次得到大约100页的结果需要花费大量时间。对于每个请求,我都使用这样的代码

$ch = curl_init();

// get source

curl_close($ch);

What are my options to speed things up?

我有哪些选项可以加快速度?

How should I use the multi_init()etc?

我应该如何使用multi_init()等?

回答by Emil Vikstr?m

  • Reuse the same cURL handler ($ch) without running curl_close. This will speed it up just a little bit.
  • Use curl_multi_initto run the processes in parallel. This can have a tremendous effect.
  • 在不运行 curl_close 的情况下重用相同的 cURL 处理程序 ($ch)。这将加快一点点。
  • 使用curl_multi_init并行运行进程。这会产生巨大的影响。

回答by urs_baer

take curl_multi - it is far better. Save the handshakes - they are not needed every time!

采取 curl_multi - 它要好得多。保存握手 - 不是每次都需要握手!

回答by abdulwadood

when i use code given in "http://php.net/curl_multi_init", response of 2 requests are conflicting. But the code written in below link, returns each response separately (in array format) https://stackoverflow.com/a/21362749/3177302

当我使用“ http://php.net/curl_multi_init”中给出的代码时,2 个请求的响应发生冲突。但是下面链接中编写的代码,分别返回每个响应(以数组格式) https://stackoverflow.com/a/21362749/3177302

回答by cuttinger

or take pcntl_fork, forksome new threads to execute curl_exec. But it's not as good as curl_multi.

或采取pcntl_forkfork一些新的线程来执行curl_exec。但它不如curl_multi.