【问题标题】:Php curl error : Hostname was NOT found in DNS cachePHP curl 错误:在 DNS 缓存中找不到主机名
【发布时间】:2015-09-05 06:47:47
【问题描述】:

我在我的专用网络服务器上上传的 php 脚本中的 curl 请求存在问题。我知道这个 curl 请求可以正常工作,因为我已经在我的本地机器上进行了测试。我认为这个问题来自我的 apache 配置或我的 DNS。但我不确定。

当我使用 curl_setopt($ch, CURLOPT_VERBOSE, true); 时,我在专用服务器上的 test_curlog.log 中收到以下错误消息:

* Rebuilt URL to: http://example.org/
* Hostname was NOT found in DNS cache
* Hostname was NOT found in DNS cache

这是我使用的代码:

<?php
var_dump("MULTI CURL REQUEST");
$error_curl_log = __DIR__ . '/../../../../web/test_curlog.log';
$fp = fopen($error_curl_log, 'a+');

// Création des ressources cURL
$ch2 = curl_init();
$ch3 = curl_init();

// Définit l'URL ainsi que d'autres options

curl_setopt($ch2, CURLOPT_URL, "http://example.org");
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_VERBOSE, true); //For debug
curl_setopt($ch2, CURLOPT_STDERR, $fp);

curl_setopt($ch3, CURLOPT_URL, "https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world");
curl_setopt($ch3, CURLOPT_HEADER, 0);
curl_setopt($ch3, CURLOPT_VERBOSE, true); //For debug
curl_setopt($ch3, CURLOPT_STDERR, $fp);

// Création du gestionnaire multiple
$mh = curl_multi_init();

// Ajoute les deux gestionnaires
curl_multi_add_handle($mh, $ch2);
curl_multi_add_handle($mh, $ch3);

$active = null;
// Exécute le gestionnaire
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) {
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
}
// Ferme les gestionnaires
curl_multi_remove_handle($mh, $ch2);
curl_multi_remove_handle($mh, $ch3);
curl_multi_close($mh);
die;

在我的本地计算机上,我在浏览器上收到以下响应:

所以我应该在我的专用服务器上得到相同的结果,但我收到了这个错误:Maximum execution time of 60 seconds exceeded,因为 curl 请求似乎找不到 URL。

任何帮助将不胜感激。

【问题讨论】:

标签: php apache curl dns bind9


【解决方案1】:

最后,我找到了解决方案。它包括在while循环中添加这个条件:

$mrc === CURLM_CALL_MULTI_PERFORM || $active

像这样:

$active = null;
// Exécute le gestionnaire
do {
    $mrc = curl_multi_exec($mh, $active);
    // Vérification des erreurs
    if($mrc > 0) {
        // Affiche le message d'erreur
        echo "ERREUR !\n " . curl_multi_strerror($mrc);
    }
} while ($mrc === CURLM_CALL_MULTI_PERFORM || $active);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) {
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
}

我不知道为什么,但它有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 2020-03-05
    • 1970-01-01
    相关资源
    最近更新 更多