Tuesday 15 February 2011

Difference between local host and server for Memory Allocation and utilization - PHP -



Difference between local host and server for Memory Allocation and utilization - PHP -

i have php script reading csv , importing values arrays calculation. have build big script on localhost using wamp , working properly. have set webserver , receiving memory error halfway through (that did not receive in local host)

to troubleshoot, have set in next code throughout segments of code:

echo memory_get_usage();

and have commented out sections , working forwards until errors out.

on segment one, have memory allocation 2.16 mb localhost , 1.29 mb webserver. on segment two, have memory allocation 2.32 mb localhost , 1.57 mb webserver.

however on segment 3 localhost 3.32 mb server next error:

fatal error: out of memory (allocated 326631424) (tried allocate 71 bytes) in /home/blablabla

does have thought cause this? file same directory , here code below. football game calculator reads historic stats calculate fantasy football game points , 194 lines long

i not programmer means , using project larn first langauge. of first bit of code wrote i'm sure needs reworked (and will) don't see error cause this. number of arrays creating? why work in localhost not webserver? using siteground hosting

thank taking time

$file_handle = fopen("football/historical/qbhist.csv", "r"); //opens historical csv file of qb while (!feof($file_handle) ) { //while end of file not reached, populate arrays listed below. $line_of_text = fgetcsv($file_handle, 1024); //line of text[n] value after each comma delimeter in 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 csv wrong - zeroes create weird results (but have effect in super super super deep leagues (like 300+ players) $pgamesplayed = 1; } if ($passydvalue == 0){ //these prevent n/0 errors. $passydvalue = 100000000000000000; } if ($rushydvalue == 0){ $rushydvalue = 100000000000000000; //these prevent n/0 errors. } if ($recydvalue == 0){ $recydvalue = 100000000000000000; //these 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 prevent duplicate scores might have effect. each player = unique score $pointsarray[$arraykey] = $qbpoints; //populates arrays calc'd points remain unsorted $namesarray[$arraykey] = $pname; //populates array player name $yeararray[$arraykey] = $pyear; //populates array year $gamesarray[$arraykey] = $pgamesplayed; //populates array games played $ptdarray[$arraykey] = $ppasstd; //populates array pass td $rtdarray[$arraykey] = $prushtd; //populates array rush td $pydarray[$arraykey] = $ppassyard; //populates array pass yards $rydarray[$arraykey] = $prushyd; //populates array rush yards $ppgarray[$arraykey] = $qbpoints / $pgamesplayed; //populates array points per game remain unsorted $ppgsortarray[$arraykey] = $qbpoints / $pgamesplayed; //populates array points per game sorted $posarray[$arraykey] = "qb"; //populates array position $pattarray[$arraykey] = $ppassatt; //populates array passatt $pcomparray[$arraykey] = $ppasscomp; //populates array passcomp $rattarray[$arraykey] = $prushatt; //populates array rushatt $pintarray[$arraykey] = $pintthr; //populates array interceptions thrown $catarray[$arraykey] = $preccat; //populates array catches $cydarray[$arraykey] = $precyd; //populates array receiving yards $ctdarray[$arraykey] = $prectd; //populates array receiving td $fumbarray[$arraykey] = $pfumblst; //populates array 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 csv silly! echo "<br>"; echo "made qb"; echo memory_get_usage();

not sure code memory allocation not static. because wamp on local machine setup handle memory usage not mean install of php on webserver is.

i suggest setting phpinfo file , compare wamp version of php hosted version. should able see differences between two. can either setup local wamp install match hosted version or inquire webhost alter theirs.

your not going have much luck on hosted end if on shared server it's worth shot.

hope helps some.

php memory memory-management fatal-error

No comments:

Post a Comment