PHP致命错误内存不足 [英] PHP Fatal error Out of memory

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

问题描述

我在名为RebuildSummary()的函数中调用以下两个函数

I am calling the below two function inside a function called RebuildSummary()

  1. create_summary()
  2. insertdatafromfile()

1. create_summary函数

create_summary函数从数据库中获取活动数据,并为每个循环使用来循环活动,然后将数据插入下面的文本文件中,如下所示:

1. create_summary function

create_summary function fetches activity data from database and loop through activities using for each loop, and insert data into the below text file like below:

A|201309|R|C|2|014000956|014000956|2200|201211|M|3118.72|35215.12|1639.96|40749.29|46183.13|44653.83|1529.3|||423|9999|EVERGREEN IMPLEMENT INC 
A|201309|R|C|2|014000956|014000956|2201|201211|M|0|13.86|0|15.22|13.86|15.22|-1.36|||423|9999|EVERGREEN IMPLEMENT INC 

2. insertdatafromfile函数

insertdatafromfile函数将读取同一文本文件的内容[zfilename71801404123.txt],并使用命令LOAD DATA将其插入到摘要表中.

2. insertdatafromfile function

insertdatafromfile function will read the contents of the same text file[zfilename71801404123.txt] and insert them into the summary table using the command LOAD DATA.

function RebuildSummary() {
    $random = date('dmyhis');
    $zfilename = "zfilename".$random;
    create_summary($zfilename);
    insertdata($zfilename);
}

function create_summary($zfilename)
{
    $activities // data from DB
    $filepath = $_SERVER['DOCUMENT_ROOT']."\z".$zfilename.".txt";
    foreach ($activities as $activity) {
        $sql_summary = "SELECT A.AcctDb as AcctDb, '" . $default->DeftReportPeriod . "' as SumReportPer, '" . $default->DeftReportBase . "' as SumReportBase, '" . $default->DeftPeriodBasis . "' as SumPeriodBasis, '" . $default->DeftBasisAdj . "' as SumBasisAdj, '" . $AcctNo . "' as AcctNo,'" . $AcctTaxId . "' as AcctTaxId, '" . $RevLoc . "' as SumRevLoc, '" . $YTDStart . "' as SumYtdStart, '" . $CurrFreq . "' as SumCurrFreq, '" . $Curr . "' as SumCurrAmt, '" . $Ytd . "' as SumYtdAmt, '" . $Lastcurr . "' as SumLastCurr, '" . $LastYTD . "' as SumLastYtd, '" . $Last12 . "' as SumLast12, '" . $Prior12 . "' as SumPrior12, '" . $Last12diff . "' as SumLast12Diff, A.AcctDateOpen as SumDateOpen, A.AcctDateClosed as SumDateClosed, A.GroupCode as SumGroupCode, A.AcctHomeLoc as SumHomeLoc, A.AcctBusName as SumBusName, A.ClassCode as SumClassCode, '" . $Currdiff . "' asSumCurrDiff, '" . $Ytddiff . "' as SumYtdDiff, '" . $Mon['0'] . "' as SumMon01, '" . $Mon['1'] . "' as SumMon02, '" . $Mon['2'] . "' as SumMon03, '" . $Mon['3'] . "' as SumMon04, '" . $Mon['4'] . "' as SumMon05, '" . $Mon['5'] . "' as SumMon06, '" . $Mon['6'] . "' as SumMon07, '" . $Mon['7'] . "' as SumMon08, '" . $Mon['8'] . "' as SumMon09, '" . $Mon['9'] . "' as SumMon10, '" . $Mon['10'] . "' as SumMon11, '" . $Mon['11'] . "' as SumMon12,'" . $Amt['0'] . "' as SumAmt01, '" . $Amt['1'] . "' as SumAmt02, '" . $Amt['2'] . "' as SumAmt03,'" . $Amt['3'] . "' as SumAmt04, '" . $Amt['4'] . "' as SumAmt05, '" . $Amt['5'] . "' as SumAmt06, '" . $Amt['6'] . "' as SumAmt07, '" . $Amt['7'] . "' as SumAmt08, '" . $Amt['8'] . "' as SumAmt09, '" . $Amt['9'] . "' as SumAmt10, '" . $Amt['10'] . "' as SumAmt11, '" . $Amt['11'] . "' as SumAmt12 FROM accounts A WHERE A.AcctDb = '" . $AcctDb . "' and A.AcctTaxId='" . $AcctTaxId . "' ;";
        $exist_activity1 = $this->db->query($sql_summary);
        $activities1 = $exist_activity1->result_array();

        $flag_index = 0;
        foreach ($activities1[0] as $key => $value) {
            if ($flag_index == 0) {
            }
            $result .= $value . "|";
            $flag_index = 1;
        }

        $j++;
        $result = rtrim($result, "|");
        $handle = fopen($filepath, 'a') or die('Cannot open file:  ' . $filepath);
        fwrite($handle, $result);
        $new_data = "\n";
        fwrite($handle, $new_data);
        $result = "";
    }
}


function insertdatafromfile($zfilename) {
    ini_set('memory_limit', '-1');
    $ext = mysql_real_escape_string("\n");
    $filepath = "z".$zfilename.".txt";
    $sqlstatement1 = "LOAD DATA INFILE " . "'" . $filepath . "'" . " 
    INTO TABLE summary
    FIELDS TERMINATED BY '|'
    LINES TERMINATED BY " . "'" . $ext . "'" . " 
    (AcctDb, SumReportPer, SumReportBase, SumPeriodBasis, SumBasisAdj, AcctNo,AcctTaxId, SumRevLoc, SumYtdStart, SumCurrFreq, SumCurrAmt, SumYtdAmt, SumLastCurr, SumLastYtd, SumLast12, SumPrior12, SumLast12Diff, SumDateOpen, SumDateClosed, SumGroupCode, SumHomeLoc, SumBusName, SumClassCode, SumCurrDiff, SumYtdDiff, SumMon01, SumMon02, SumMon03, SumMon04, SumMon05, SumMon06, SumMon07, SumMon08, SumMon09, SumMon10, SumMon11, SumMon12, SumAmt01, SumAmt02, SumAmt03, SumAmt04, SumAmt05, SumAmt06, SumAmt07, SumAmt08, SumAmt09, SumAmt10, SumAmt11, SumAmt12)
";
    mysql_query($sqlstatement1);
    $filepath = $_SERVER['DOCUMENT_ROOT']."\z".$zfilename.".txt";
    unlink($filepath);
}

系统配置:

Processor: Intel(R) Xeon(TM) CPU 2.80Ghz, 2.79 Ghz (2 Processors)
Installed memory(RAM) : 6.00 GB
System Type: 64 bit Operating System
Server: Windows IIS 7

PHPINFO

max_input_time: 60000
max_file_uploads: 2048M
memory_limit: 20000M
post_max_size: 20000M
upload_max_filesize: 15000M

我的问题:

调用RebuildSummary函数时出现以下错误.

My Question:

I am getting the below error while calling the RebuildSummary function.

[17-Apr-2014 03:54:42 America/Los_Angeles] PHP Fatal error:  Out of memory (allocated 1517289472) (tried to allocate 64 bytes) in C:\HostingSpaces\wwwroot\system\database\drivers\mysql\mysql_result.php on line 162

我在服务器端有足够的内存,仍然是系统如何显示此错误内存不足"

I have enough memory on server side, still how the system display this error "Out of memory"

推荐答案

1517289472 bytes ~= 1.4G,所以您在附近遇到了障碍

1517289472 bytes ~= 1.4G so you're hitting a barrier around there

首先要注意的是设置memory_limit: 20000M,即20G.您的系统上只有6G. PHP可能会令人困惑,默认情况下是一个较低的限制,或者您的Windows 7上运行的php版本可能存在硬限制.

The first thing you should look at is you're setting memory_limit: 20000M which is 20G. You've only 6G on your system. PHP may be confused and defaulting to a lower limit or there may be a hard limit for your version of php running on windows 7.

或者您可能正在运行32位Apache/PHP进程,这些进程对2G都有严格的限制,请参见:

OR you could be running 32 bit Apache/PHP processes, which have hard limits around 2G see this: Upper memory limit for PHP/Apache

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

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