DOMDocument PHP Memory Leak(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();
}
推荐答案
Using 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) . "
"; flush();
}
?>
这篇关于DOMDocument PHP 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DOMDocument PHP 内存泄漏


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01