PHP简单的HTML Dom内存问题 [英] PHP Simple HTML Dom Memory Issue

查看:96
本文介绍了PHP简单的HTML Dom内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遇到PHP Simple HTML DOM Parser的内存问题。我正在解析一个公平的文档,需要运行DOM树...



1)我从整个文件开始:

  $ html = file_get_html($ file); 

2)然后解析我的表:

  $ table = $ html-> find('table.big'); 

3)然后解析出我的行:

  $ rows = $ table [0]  - > find('tr'); 

我最终结束的是三个GIANT对象...任何人都知道如何转储对象在我解析了我需要的数据之后?像$ html一样,在步骤3中是无用的,但它是所有对象中最大的。



任何想法?



有没有办法向下钻取我的表格中的原始$ html目的?



提前感谢



编辑:



我已经设法跳过第二步:

  $ rows = $ this-> html-> find(' table.big tr'); 

但仍然遇到内存问题...

解决方案

如果内存真的是一个很大的问题,你可能想查看 SAX 而不是使用DOM。在获得 $ table 后,您可能需要在 $ html 上尝试 unset() code>,但这只是标记为垃圾回收,而内存不会立即被释放



在一天结束的时候,这是真正由编写内存效率的简单HTML DOM或您选择的实现。


I'm running into memory issues with PHP Simple HTML DOM Parser. I'm parsing a fair sized doc and need to run down the DOM tree...

1)I'm starting with the whole file:

$html = file_get_html($file);

2)then parsing out my table:

$table = $html->find('table.big'); 

3)then parsing out my rows:

$rows = $table[0]->find('tr');

What I'm ending up with are three GIANT objects... anyone know how to dump an object after I've parsed it for the data I need? Like $html is useless by step 3, yet, it's the largest of all the objects.

Any ideas?

Is there a way to drill down to my table rows out of the original $html object?

Thanks in advance.

EDIT:

I've managed to skip step two with:

$rows = $this->html->find('table.big tr');

But am still running into memory issues...

解决方案

If memory is really a big concern, you may want to look into SAX instead of using DOM. You may want to try unset() on the $html after obtaining $table, but that is simply just marking it to be garbage collected and memory won't be freed up immediately.

At the end of the day, it is really up to how memory-efficient Simple HTML DOM is written or which implementation you have chosen.

这篇关于PHP简单的HTML Dom内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆