-
-
Save xtepwxly/8fca682efc496785eb41 to your computer and use it in GitHub Desktop.
curl sucks or I suck? :D
This file contains hidden or 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
$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