【问题标题】:execute 2 cURL functions concurrently and randomly同时随机执行 2 个 cURL 函数
【发布时间】:2012-08-02 07:25:02
【问题描述】:

我想知道是否可以同时随机执行两个 post_to_url 函数—— post_to_url 函数是一个 cURL 请求,而 $data 是来自表单的变量。我试图用 curl_multi 句柄重写 post_to_url 函数,但它不起作用。感谢您的帮助 - 非常感谢。

$urls = array(
   "http://examplesite1.com/cgi-bin/maxuseradmin.cgi",
   "http://examplesite2?fid=6646588e54",
   "http://examplesite1?fid=2fb44e3888"
);

$data = array(
    $data2,
    $data3,
    $data4
);
$x = rand(0,2);
post_to_url($urls[x], $data[x]);
post_to_url($urls[x], $data[x]);

【问题讨论】:

  • 你总是可以尝试多线程:stackoverflow.com/questions/70855/…
  • 或者您可能想查看async sockets。在这种情况下它可能会更简单,特别是如果您设法找到一个使用异步套接字的不错的 HTTP 库。
  • 嗨 Vatev,我对更高级的 php 类型的东西有点陌生。有没有一个小例子可以帮助我上路?谢谢

标签: php curl


【解决方案1】:

试试这个课程

http://peecfw.googlecode.com/svn/trunk/Application/com/loadable/curl/CURL_thread.php

你可以这样称呼它

$cURL = new CURL();
$cURL->addSession("https://www.example.com/?data=test");
$cURL->addSession("https://www.example2.com/?data=test");
$responses = $cURL->exec();  //This array will contain all responses
$cURL->clear();

【讨论】:

    猜你喜欢
    • 2014-12-25
    • 1970-01-01
    • 2021-08-09
    • 2017-04-11
    • 2018-09-04
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多