0
我試圖保存3個XML URL鏈接寫入它們的本地xml緩存副本。但有2個XML url鏈接參數後傳遞?根本沒有儲蓄?PHP CURL保存多個XML url鏈接?
只有allteams.xml被保存到multicache文件夾中,而其他2個url不會被保存?
必須有更好的方法來做到這一點?
<?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_CONNECTTIMEOUT,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);
?>
感謝