When trying to connect to the Twitter api using cUrl and PHP, I get the following error:
Couldn't resolve host 'search.twitter.com'
Before it worked fine, and the request works in my browser. When trying to connect to example.com, I do get the page. I've also tried the following code, with which I get the same error:
$_h = curl_init();curl_setopt($_h, CURLOPT_HEADER, 1);
curl_setopt($_h, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($_h, CURLOPT_HTTPGET, 1);
curl_setopt($_h, CURLOPT_URL, 'http://www.example.com' );
curl_setopt($_h, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
curl_setopt($_h, CURLOPT_DNS_CACHE_TIMEOUT, 2 );
$json_url = "https://search.twitter.com/search.json?q=" . 'bitterrific' . "&rpp=10&result_type=all";
$ch = curl_init();
$timeout = 100;
$data = curl_exec($ch);
$content = json_decode($data);
$output = array();
echo "DATA: ".curl_error($ch);
I didn't found a problem with your code.
Also search.twitter.com works:
$ host search.twitter.com search.twitter.com is an alias for s.twitter.com. s.twitter.com has address 22.214.171.124 s.twitter.com has address 126.96.36.199 s.twitter.com has address 188.8.131.52
You should check your server's DNS settings.
You also ask for other ways to fetch json data with PHP. PHP accepts urls to be used as remote files. So you could try something like:
$content = file_get_contents("https://search.twitter.com/search.json?q=" . 'bitterrific' . "&rpp=10&result_type=all"); $content = json_decode($content); var_dump($content);