I have a PHP script where i am reading from a csv and importing values into arrays for calculation. I have build this large script on localhost using WAMP and everything is working properly. I have put it into a webserver now and am receiving a memory error about halfway through (that i did not receive in local host)
to troubleshoot, i have put in the following code throughout segments of my code:
echo memory_get_usage();
and have commented out all the sections and working forward until it errors out.
on segment one, i have memory allocation 2.16 MB for localhost and 1.29 MB for webserver. on segment two, i have memory allocation 2.32 MB for localhost and 1.57 MB for webserver.
however on segment three i get for localhost 3.32 MB but for server i get the following error:
Fatal error: Out of memory (allocated 326631424) (tried to allocate 71 bytes) in /home/blablabla
does anybody have an idea what would cause this? the file is from the same directory and here is the code below. It is for a football calculator that reads historic stats to calculate fantasy football points and is only 194 lines long
I am not a good programmer by any means and am using this project to essentially learn my first langauge. this was some of the first bit of code i wrote so i'm sure it needs reworked (and i probably will) but i don't see the error what would cause this. is it the number of arrays i am creating? why will it work in localhost but not webserver? using siteground as hosting
Thank you for anyone taking the time
$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();