PHP 内存不足 - 使 Apache 崩溃? [英] PHP Out of Memory - Crashes Apache?

查看:24
本文介绍了PHP 内存不足 - 使 Apache 崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 PHP 5.3.0 版和 Apache:2.2.11

I am running PHP version 5.3.0 and Apache: 2.2.11

当我运行消耗大量内存的 PHP 脚本时(我认为) - 大循环等.我的 Apache Web 服务器报告崩溃?!

When I run PHP scripts that consume a lot of memory (I think) - large loops etc. My Apache web server reports a crash?!

[Sat Jan 02 00:51:30 2010] [notice] Parent: child process exited with status 255 -- Restarting.

我需要在某处增加内存吗?我目前将内存设置为

Do I need to increase memory somewhere? I currently have memory set to

memory_limit = 512M 

PHP 没有抱怨过这个问题,所以我在想它是别的什么?

PHP hasn't complained about this so I am thinking its something else?

谢谢大家

我的windows机器在事件查看器中记录了这个错误:

This error has been logged by my windows machine in the event viewer:

错误的应用程序 httpd.exe,版本 2.2.11.0,时间戳0x493f5d44,故障模块php5ts.dll,版本5.3.0.0,时间戳 0x4a4922e7,异常代码0xc0000005,故障偏移0x00083655,进程 ID 0x1588,应用程序启动时间 0x01ca8b46e4925f90.

Faulting application httpd.exe, version 2.2.11.0, time stamp 0x493f5d44, faulting module php5ts.dll, version 5.3.0.0, time stamp 0x4a4922e7, exception code 0xc0000005, fault offset 0x00083655, process id 0x1588, application start time 0x01ca8b46e4925f90.

更新 2

有问题的脚本.我已删除该网址.

Update 2

Script in question. I've removed the URL.

<?php error_reporting(E_ALL);

set_time_limit(300000);

echo 'start<br>';

include_once('simple_html_dom.php');

$FileHandle = fopen('tech-statistics3.csv', 'a+') or die("can't open file");

for($i =1; $i < 101; $i ++){
 // Create DOM from URL
 $html = file_get_html("http://www.x.com/$i");

 foreach($html->find('div[class=excerpt]') as $article) {

  $item0 = $article->children(1)->children(1)->children[0]->plaintext;

  $item1 = $article->children(1)->children(1)->children[0]->plaintext;

  $item2 = $article->children(1)->children(0)->children(0)->children(0)->plaintext;

  //$item3 = $article->children(1)->children(0)->children(0)->children[1]->children(0)->next_sibling();

  $stringa = trim($item0).",".trim($item1).",".trim($item2)."\r\n";

  fwrite($FileHandle, $stringa);

  echo $stringa.'<br>';
  echo '------------>'.$i;
 }
}

fclose($FileHandle);

echo '<b>End<br>';

?>

更新 3

我正在使用 PHP Simple HTML DOM Parser,我刚刚发现了这个:

Update 3

I am using the PHP Simple HTML DOM Parser and I have just found this:

http://simplehtmldom.sourceforge.net/manual_faq.htm#memory_leak

我想我应该清除内存,否则它会崩溃.立即测试.

I think I should be clearing memory otherwise it will crash. Testing now.

是的,这是内存泄漏!:)

Yep, it was a memory leak! :)

推荐答案

由于没有关闭在 for 循环中反复使用的资源以及脚本导致的内存泄漏,Apache 崩溃了使用递归.

Apache was crashing due to a memory leak which was caused by not closing a resource that was being used again and again in a for loop, as well as the script making use of recursion.

感谢大家的帮助.

这篇关于PHP 内存不足 - 使 Apache 崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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