在PHP中解析一个巨大的XML数组
我想从中获取数据。每次我点击这个URL,浏览器就会卡住。我试图通过curl和在PHP中解析一个巨大的XML数组,php,xml,Php,Xml,我想从中获取数据。每次我点击这个URL,浏览器就会卡住。我试图通过curl和file\u get\u contents()直接命中它,但结果是一样的 这个URL发送一个巨大的Xml,我必须从中获取并收集所需的信息,并将其保存在数据库中 请帮助我完成此任务,或者至少告诉我如何获取此XML?我甚至无法在我的浏览器上加载该文件,因此我猜它太大了,您应该尝试以某种方式限制加载量(是否有参数允许您仅指定一个城市?),但是,如果没有选择,有一个类可以大致完成你想要的任务。只能确保传递URL,而不是CURL请
file\u get\u contents()
直接命中它,但结果是一样的
这个URL发送一个巨大的Xml,我必须从中获取并收集所需的信息,并将其保存在数据库中
请帮助我完成此任务,或者至少告诉我如何获取此XML?我甚至无法在我的浏览器上加载该文件,因此我猜它太大了,您应该尝试以某种方式限制加载量(是否有参数允许您仅指定一个城市?),但是,如果没有选择,有一个类可以大致完成你想要的任务。只能确保传递URL,而不是
CURL
请求的内容。URLhttp://www.livingsocial.com/cities.atom
非常大(94354882字节,约为90MB),需要花费时间加载(此处为33秒)
由于这是一个远程资源,您无法更改它
但是,如果将该提要存储到磁盘(缓存它),则可以将文件加载到Simplexml或DOMDocument的时间缩短约1.5秒
// Store URL to disk (takes ca. 33 seconds)
$url = 'http://www.livingsocial.com/cities.atom';
$out = 'cities.atom.xml';
$fh = fopen($url, 'r');
$r = file_put_contents($out, $fh);
fclose($fh);
如果仍然太慢,您不仅需要缓存远程文件,还需要解析。一旦我遇到同样的问题。。要在chrome中打开此URL的文件内容,请在1或2秒钟后停止。。它将显示xml的结构。。 完成最后的1或2个标签,并享受。。我正在把结构粘贴在这里
<?xml version="1.0"?>
<feed xmlns:ls="http://livingsocial.com/ns/1.0" xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" xml:lang="en-US">
<title>LivingSocial Deals</title>
<updated>2013-03-12T00:49:21-04:00</updated>
<id>tag:livingsocial.com,2005:/cities.atom</id>
<link rel="alternate" type="text/html" href="http://www.livingsocial.com/"/>
<link rel="self" type="application/atom+xml" href="http://www.livingsocial.com/cities.atom"/>
<entry>
<id></id>
<published></published>
<updated></updated>
<link type="text/html" href="http://www.livingsocial.com/cities/1759-sacramento-citywide/deals/620554-set-of-two-organic-yoga-leggings" rel="alternate"/>
<title></title>
<long_title></long_title>
<deal_type></deal_type>
<merchandise_type></merchandise_type>
<market_id></market_id>
<market_name></market_name>
<georss:point></georss:point>
<georss:featureTypeTag>city</georss:featureTypeTag>
<country_code>US</country_code>
<subtitle></subtitle>
<offer_ends_at></offer_ends_at>
<price></price>
<value></value>
<savings></savings>
<orders_count></orders_count>
<merchant_name></merchant_name>
<image_url></image_url>
<categories></categories>
<sold_out></sold_out>
<national></national>
<description></description>
<details></details>
<content type="html"></content>
<ls:merchant></ls:merchant>
<author>
<name></name>
</author>
</entry>
</feed>
</xml>
生活社会交易
2013-03-12T00:49:21-04:00
标签:livingsocial.com,2005:/cities.atom
城市
美国
“我们找不到该页面。”@Gordon请尝试编辑的版本。自动链接器正在拾取“.Each”。这里是livingsocial.com/cities.atom。请查看是否有帮助。Gordon尝试此url livingsocial.com/cities.atom。然后您将找出我遇到的问题。不,此解决方案根本不起作用,而是标记以下错误消息:错误:无法打开hhttp://livingsocial.com/cities.atom