Skip to content

Instantly share code, notes, and snippets.

@xtepwxly
Last active September 12, 2015 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtepwxly/8fca682efc496785eb41 to your computer and use it in GitHub Desktop.
Save xtepwxly/8fca682efc496785eb41 to your computer and use it in GitHub Desktop.
curl sucks or I suck? :D
$years = array('2012', '2013', '2014', '2015');
foreach($years as $year)
{
$url = "http://lpo.dt.navy.mil/data/DM/Environmental_Data_Deep_Moor_{$year}.txt";
$fp = fopen(base_path() . "/database/rawdata/{$year}.txt", 'w');
$curl = curl_multi_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_FILE => $fp,
CURLOPT_VERBOSE => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FAILONERROR => 1
));
curl_exec($curl);
if (!curl_errno($curl))
{
$info = curl_getinfo($curl);
Log::info("File created {$year}.txt");
Log::notice("Evaluation of this script was {$info['total_time']} seconds!");
}
else
{
Log::error("cURL ERROR " . curl_error($curl));
}
curl_close($curl);
fclose($fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment