curl_multi_exec不调用远程函数

时间:2014-12-25 04:26:28

标签: php curl

我有一个Utility类,必须通过cURL调用远程cPanel URL来创建电子邮件转发地址。如果我使用常规curl_exec,但是如果我尝试通过curl_multi_exec使其无阻塞,那么这非常有效 - 我需要做的就是发送请求并继续前进,我不需要知道结果 - 所以这是一个真正的非阻止要求

以下是有效的代码

$url = "https://mycpanel.com:2083/execute/Email/add_forwarder?domain=mydomain.com&email=email_fwd_146&fwdopt=pipe&pipefwd=php/piper.php&";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("user:pwd")));

$response = curl_exec($ch);
CakeLog::write('error', print_r($response, true));
curl_close($ch);

上面代码的响应如下(即使我真的不关心响应)

{
    "messages":null,
    "errors":null,
    "status":1,
    "metadata":{
        "transformed":1
        },
    "data":[
        {
            "email":"email_fwd_146@mydomain.com",
            "domain":"mydomain.com",
            "forward":"|/home/myconsole/php/piper.php"
        }]
}

以下是不起作用的代码

$url = "https://mycpanel.com:2083/execute/Email/add_forwarder?domain=mydomain.com&email=email_fwd_146&fwdopt=pipe&pipefwd=php/piper.php&";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("user:pwd")));

$mh = curl_multi_init();
curl_multi_add_handle($mh,$ch);
curl_multi_exec($mh, $active);

此调用似乎永远不会到达服务器甚至执行。任何见解都将受到赞赏。

1 个答案:

答案 0 :(得分:0)

这是因为需要一遍又一遍地调用curl_multi_exec(),直到传输完成。