我的客户要求我实现一个联属提要,其格式为XML。然而,这个文件很大,有650k行!我试着使用simpleXML解析它,它工作了,但它非常慢。因此,网站有时无法加载。
<?php
$html = "";
$url = "http://www.digitick.com/rss/distributeur/fluxAffiliation195_815.xml";
$xml = simplexml_load_file($url);
for($i = 0; $i < 10; $i++){
$title = $xml->content->eventList->event[$i]->eventName;
$link = $xml->content->eventList->event[$i]->eventUrl;
$description = $xml->content->eventList->event[$i]->eventPresentation;
$dateStart = $xml->content->eventList->event[$i]->dateStart;
$img = $xml->content->eventList->event[$i]->pictureUrl;
$html .= "<a href='$link'><h3>$title</h3></a>";
$html .= "<img src=$img>";
$html .= "$description";
$html .= "<br />$dateStart<hr />";
}
echo $html;
?>我能做什么来处理这个动态文件(它每天早上5点更新?
提前谢谢你!
发布于 2017-02-07 22:26:28
我将使用cron作业将文件导入到SQLite数据库文件中。然后在您的应用程序中使用SQL请求其中的一部分。作为替代方案,缓存生成的输出,每天只读取一次大文件。
https://stackoverflow.com/questions/42087738
复制相似问题