PHP 多个 Curl 请求

发布于 2024-09-27 00:06:18 字数 208 浏览 1 评论 0原文

我目前经常使用 PHP 的 Curl。每次获取100页左右的结果需要花费很多时间。对于每个请求,我都使用这样的代码:

$ch = curl_init();

// get source

curl_close($ch);

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

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

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

$ch = curl_init();

// get source

curl_close($ch);

What are my options to speed things up?

How should I use the multi_init() etc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦途 2024-10-04 00:06:18
  • 重用相同的 cURL 处理程序 ($ch),而不运行 curl_close。这会稍微加快速度。
  • 使用 curl_multi_init 并行运行进程。这会产生巨大的影响。
  • Reuse the same cURL handler ($ch) without running curl_close. This will speed it up just a little bit.
  • Use curl_multi_init to run the processes in parallel. This can have a tremendous effect.
黄昏下泛黄的笔记 2024-10-04 00:06:18

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

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

悟红尘 2024-10-04 00:06:18

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

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

孤君无依 2024-10-04 00:06:18

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文