PHP CURL saving multiple XML url links?
I'm trying to save 3 XML url links to write to local xml cache copy of them. But 2 of the XML url links with parameters passed after ? aren't saving at all ?
only allteams.xml gets saved into multicache folder while other 2 urls don't get saved ?
there must be a better way to do this ?
<?php
$urls=array(
'http://remotedomain.com/api/team.xml?id=12',
'http://remotedomain.com/api/allteams.xml',
'http://remotedomain.com/api/allmembers.xml?limit=1000&id=12');
$save_to='multicache/';
$mh = curl_multi_init();
foreach ($urls as $i => $url) {
$g=$save_to.basename($url);
if(!is_file($g)){
$conn[$i]=curl_init($url);
$fp[$i]=fopen ($g, "w");
curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]);
curl_setopt ($conn[$i], CURLOPT_HEADER ,0);
curl_setopt($conn[$i],CURLOPT_CONNECTTIME开发者_开发技巧OUT,60);
curl_multi_add_handle ($mh,$conn[$i]);
}
}
do {
$n=curl_multi_exec($mh,$active);
}
while ($active);
foreach ($urls as $i => $url) {
curl_multi_remove_handle($mh,$conn[$i]);
curl_close($conn[$i]);
fclose ($fp[$i]);
}
curl_multi_close($mh);
?>
thanks
Hmm, how about some low-tech solution:
foreach ($urls as $url)
{
copy($url, $save_to . basename($url));
}
No curl, just some basic PHP streams.
I'm not sure about that is_file()
business, if you want to check that the file doesn't exist, use file_exists()
.
精彩评论