DOMDocument PHP内存泄漏 [英] DOMDocument PHP Memory Leak

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

问题描述

在MAC上的MAMP下运行PHP 5.3.6,内存使用量每增加x次调用(介于3和8之间),直到脚本因内存耗尽而死.我该如何解决?

Running PHP 5.3.6 under MAMP on MAC, the memory usage increases every x calls (between 3 and 8) until the script dies from memory exhaustion. How do I fix this?

libxml_use_internal_errors(true);
while(true){
 $dom = new DOMDocument();
 $dom->loadHTML(file_get_contents('http://www.ebay.com/'));
 unset($dom);
 echo memory_get_peak_usage(true) . '<br>'; flush();
}

推荐答案

使用libxml_use_internal_errors(true);抑制错误输出,但建立连续的错误日志,该日志将附加到每个循环中.禁用内部日志记录并禁止PHP警告,或者在每次循环迭代时清除内部日志,如下所示:

Using libxml_use_internal_errors(true); suppresses error output but builds a continuous log of errors which is appended to on each loop. Either disable the internal logging and suppress PHP warnings, or clear the internal log on each loop iteration like this:

<?php
libxml_use_internal_errors(true);
while(true){
 $dom = new DOMDocument();
 $dom->loadHTML(file_get_contents('ebay.html'));
 unset($dom);
 libxml_use_internal_errors(false);
 libxml_use_internal_errors(true);
 echo memory_get_peak_usage(true) . "\r\n"; flush();
}
?>

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

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