Created
April 3, 2012 15:47
-
-
Save jonathantneal/2293056 to your computer and use it in GitHub Desktop.
Curling caniuse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$referer = 'http://caniuse.com/index.php'; | |
$url = 'http://caniuse.com/jsonp.php'; | |
$user_agent = 'Mozilla/5.0 (compatible; Linux) Curl/1.0'; | |
$file = 'data.json'; | |
$curl_handle = curl_init(); | |
curl_setopt($curl_handle, CURLOPT_URL, $url); | |
curl_setopt($curl_handle, CURLOPT_HEADER, 0); | |
curl_setopt($curl_handle, CURLOPT_REFERER, $referer); | |
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 2); | |
curl_setopt($curl_handle, CURLOPT_USERAGENT, $user_agent); | |
$buffer = curl_exec($curl_handle); | |
curl_close($curl_handle); | |
if (!empty($buffer)) { | |
file_put_contents($file, $current); | |
} else { | |
exit(new Exception('No buffer returned.')); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment