Home » Php » Failed to connect to news.google.com port 80

Failed to connect to news.google.com port 80

Posted by: admin October 26, 2017 Leave a comment

Questions:

I have below code for fetching the feed from google news. It’s working fine for a few time. If we try to call this function more than 2 or 3 in a small time it shows an error.

$url="http://news.google.com/news?q=Stella+Artois&hl=en&um=1&ie=UTF-8&output=rss";
$ch = curl_init();

curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);       

$data = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($data, 0, $header_size);
$body = substr($data, $header_size);
if(curl_error($ch)){
    echo 'error:' . curl_error($ch);
}
curl_close($ch);

error:Failed to connect to news.google.com port 80: Connection refused

I know the reason was, the google will block the access after a few request. SI there anything can do? I am using linux server.

Answers:

Yes Google will block is after repeated attempts and might even respond to curl requests altogether. You should use an API – https://newsapi.org/google-news-api

Questions:
Answers:

After trying many options,i found an alternative api,which is working good now rss2json.com

API call : https://api.rss2json.com/v1/api.json?rss_url=http%3A%2F%2Fnews.google.com%2Fnews%3Fq%3Dyahoo%26hl%3Den%26um%3D1%26ie%3DUTF-8%26output%3Drss