【发布时间】:2014-12-12 11:58:18
【问题描述】:
我有一个 PHP 脚本,我从 csv 读取数据并将值导入到数组中进行计算。我已经使用 WAMP 在 localhost 上构建了这个大型脚本,并且一切正常。我现在已将其放入网络服务器,并且大约在中途收到内存错误(我没有在本地主机中收到)
为了排除故障,我在我的代码段中加入了以下代码:
echo memory_get_usage();
并已注释掉所有部分并继续工作,直到出错为止。
在第一段,我为本地主机分配了 2.16 MB 的内存,为网络服务器分配了 1.29 MB。 在第二段,我为本地主机分配了 2.32 MB 的内存,为网络服务器分配了 1.57 MB。
但是在第三段我得到 localhost 3.32 MB 但对于服务器我得到以下错误:
致命错误:内存不足(分配326631424)(试图分配71 字节)在/home/blablabla
有人知道是什么原因造成的吗?该文件来自同一目录,下面是代码。这是一个足球计算器,可以读取历史数据来计算梦幻足球积分,只有 194 行
无论如何,我都不是一个优秀的程序员,我正在使用这个项目来学习我的第一门语言。这是我写的第一段代码,所以我确定它需要重做(我可能会),但我没有看到导致这种情况的错误。是我正在创建的数组数量吗?为什么它可以在 localhost 但不能在网络服务器中工作?使用siteground作为主机
感谢您抽出宝贵时间
$file_handle = fopen("football/Historical/QBHIST.csv", "r"); //opens historical csv file of qb
while (!feof($file_handle) ) { //while the end of file is not reached, populate arrays as listed below.
$line_of_text = fgetcsv($file_handle, 1024); //line of text[n] is the value after each comma delimeter in the handle file
$PName = $line_of_text[0]; //player name
$PTeam = $line_of_text[1]; //team
$PPlays = $line_of_text[2]; //plays played
$PGamesPlayed = $line_of_text[3]; //games played
$PRushAtt = $line_of_text[4]; //rush attempts
$PRushYd = $line_of_text[5]; //rush yards
$PRushTD = $line_of_text[6]; //rush td
$PPassAtt = $line_of_text[7]; //pass attempts
$PPassComp = $line_of_text[8]; //pass completions
$PPassYard = $line_of_text[9]; //pass yards
$PPassTD = $line_of_text[10]; //pass td
$PFumbLst = $line_of_text[11]; //fumbles lost
$PIntThr = $line_of_text[12]; //interceptions thrown
$PYear = $line_of_text[13]; //season year
$PPos = $line_of_text[14]; //player position
$PRecTD = $line_of_text[15]; //receiving td
$PRecYd = $line_of_text[16]; //receiving yards
$PRecCat = $line_of_text[17]; //receptions
$PRecTar = $line_of_text[18]; //targets
$PRecDrp = $line_of_text[19]; //drops
$PIncThr = $PPassAtt - $PPassComp; //pass incompletions
if ($PGamesPlayed <= 0){ //in case the CSV is wrong - Zeroes create weird results (but only have an effect in SUPER SUPER SUPER deep leagues (like 300+ players)
$PGamesPlayed = 1;
}
if ($PassYdValue == 0){ //these are to prevent n/0 errors.
$PassYdValue = 100000000000000000;
}
if ($RushYdValue == 0){
$RushYdValue = 100000000000000000; //these are to prevent n/0 errors.
}
if ($RecYdValue == 0){
$RecYdValue = 100000000000000000; //these are to prevent n/0 errors.
}
//points scored formula
$QBPoints =
($PPassTD * $PassTdValue) +
($PPassYard / $PassYdValue) +
($PPassComp * $PassCompValue) +
($PIntThr * $PassIntValue) +
($PIncThr * $PassIncValue) +
($PPassAtt * $PassAttValue) +
($PRushAtt * $RushAttValue) +
($PRushTD * $RushTdValue) +
($PRushYd / $RushYdValue) +
($RushFumbValue * $PFumbLst) +
($PRecTD * $RecTdValue) +
($PRecYd / $RecYdValue) +
($PRecTar * $RecTarValue) +
($PRecCat * $RecCatValue) +
($ArrayKey / 10000000)* -1; //this arraykey/billion is to prevent duplicate scores that might have an effect. each player = unique score
$PointsArray[$ArrayKey] = $QBPoints; //populates arrays for calc'd points to remain UNSORTED
$NamesArray[$ArrayKey] = $PName; //populates array for player name
$YearArray[$ArrayKey] = $PYear; //populates array for year
$GamesArray[$ArrayKey] = $PGamesPlayed; //populates array for games played
$PTDArray[$ArrayKey] = $PPassTD; //populates array for pass td
$RTDArray[$ArrayKey] = $PRushTD; //populates array for rush td
$PYdArray[$ArrayKey] = $PPassYard; //populates array for pass yards
$RYdArray[$ArrayKey] = $PRushYd; //populates array for rush yards
$PPGArray[$ArrayKey] = $QBPoints / $PGamesPlayed; //populates array for Points per game to remain UNSORTED
$PPGSortArray[$ArrayKey] = $QBPoints / $PGamesPlayed; //populates array for Points per game to be SORTED
$PosArray[$ArrayKey] = "QB"; //populates array for position
$PAttArray[$ArrayKey] = $PPassAtt; //populates array for PassATT
$PCompArray[$ArrayKey] = $PPassComp; //populates array for PassComp
$RAttArray[$ArrayKey] = $PRushAtt; //populates array for RushATT
$PIntArray[$ArrayKey] = $PIntThr; //populates array for interceptions thrown
$CatArray[$ArrayKey] = $PRecCat; //populates array for Catches
$CYdArray[$ArrayKey] = $PRecYd; //populates array for receiving yards
$CTDArray[$ArrayKey] = $PRecTD; //populates array for receiving TD
$FumbArray[$ArrayKey] = $PFumbLst; //populates array for fumbles
$ArrayKey = $ArrayKey + 1;
}
array_pop($PointsArray);
array_pop($NamesArray);
array_pop($YearArray);
array_pop($GamesArray);
array_pop($PTDArray);
array_pop($RTDArray);
array_pop($PYdArray);
array_pop($RYdArray);
array_pop($PPGArray);
array_pop($PPGSortArray);
array_pop($PosArray);
array_pop($PAttArray);
array_pop($RAttArray);
array_pop($PIntArray);
array_pop($CatArray);
array_pop($CYdArray);
array_pop($CTDArray);
//array_pop($GamesArray);
fclose($file_handle); //close your csv silly!
echo "<br>";
echo "made it to QB";
echo memory_get_usage();
【问题讨论】:
-
当您在代码中提到“段”时,您到底在说什么?另外,发生错误的行号的代码行是什么?
标签: php memory memory-management fatal-error