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

查看:194
本文介绍了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,异常code
  0000005,故障偏移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.

脚本问题。我已经删除的URL。

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简单的HTML DOM解析器,我刚刚发现这一点:

Update 3

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

<一个href=\"http://simplehtmldom.sourceforge.net/manual_faq.htm#memory_leak\">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! :)

推荐答案

阿帕奇崩溃,由于这是由不打烊正在被反复使用的循环资源,以及脚本导致内存泄漏利用递归的。

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天全站免登陆