2014-10-17 63 views
0

我有一個PHP腳本,其中我正在讀取一個csv並將值導入數組進行計算。我已經使用WAMP在本地主機上構建了這個大腳本,並且一切正常。我已經把它變成一個Web服務器現在正在通過接收大約一半的內存錯誤(我沒有在本地主機接收)本地主機和服務器之間的內存分配和利用差異 - PHP

解決,我已經把下面的代碼貫穿於我的代碼段:

echo memory_get_usage(); 

並已註釋掉所有部分,並一直工作直到它出錯。

段1,我有內存分配2.16 MB的本地主機和1.29 MB的網絡服務器。 在第二段,我有內存分配2.32 MB的本地主機和1.57 MB的網絡服務器。

然而上段三個I得到本地主機3.32 MB,但對於服務器我得到以下錯誤:

Fatal error: Out of memory (allocated 326631424) (tried to allocate 71 bytes) in /home/blablabla

沒有任何人有一個想法是什麼會導致此?該文件來自同一個目錄,這裏是下面的代碼。這是一個足球計算器,讀取歷史統計數據來計算幻想足球積分,只有194線長

我不是一個很好的程序員,我正在使用這個項目來從根本上學習我的第一個語言。這是我寫的第一部分代碼,所以我確信它需要重新編寫(而且我可能會這麼做),但是我沒有看到錯誤會導致這種情況。它是我創建的陣列的數量?爲什麼它會在localhost而不是web服務器上運行?使用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(); 
+0

當你在代碼中引用「段」時,你到底在說什麼?此外,錯誤發生的行號處的代碼行是什麼? – Crackertastic 2014-10-17 01:19:28

回答

1

不完全確定的代碼本身,而是內存分配也不是一成不變的。僅僅因爲本地機器上的WAMP設置爲處理內存使用情況並不意味着在您的Web服務器上安裝PHP。

我會建議設置一個phpinfo文件並將您的WAMP版本的php與您的託管版本進行比較。你應該能夠快速看到兩者之間的差異。您可以設置您的本地WAMP安裝以匹配您的託管版本,或者讓您的虛擬主機更改它們。

如果您在共享服務器上,但您值得一試,您可能不會在託管端獲得太多運氣。

希望有助於一些。

+0

謝謝 - 我沒有意識到配置差異。主機使用了比我的副本更早的php版本,並且存在一個大小寫敏感的錯誤,我最終追查到了這個錯誤。你的建議爲這一發現鋪平了道路。謝謝 – kamelkid2 2014-10-17 11:19:25

相關問題