谷歌ping失败 - cURL

时间:2013-11-14 10:12:52

标签: php curl

我在更新Sitemap时尝试ping Google但总是得到回复'0'

以下是我正在尝试的内容:

$sitemapUrl = urlencode("http://testsite.com/Sitemap.xml");

// cUrl handler to ping the Sitemap submission URLs for Search Engines…

function myCurl($url) {

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $httpCode;

}

//Google
$url = "http: //www.google.com/webmasters/tools/ping?sitemap=".$sitemapUrl;
$returnCode = myCurl($url);
echo = "<p> Google Sitemaps has been pinged (return code: $returnCode). </p>";

返回:

Google Sitemaps has been pinged (return code: 0). 

1 个答案:

答案 0 :(得分:0)

您需要添加这些参数,因为 Google 会在 HTTPS/SSL 协议上运行。

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);