doushu9253 2014-10-17 00:07
浏览 36
已采纳

用于内存分配和利用的本地主机和服务器之间的区别 - PHP

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();
  • 写回答

1条回答 默认 最新

  • dongpu1315 2014-10-17 01:19
    关注

    Not exactly sure about the code itself but memory allocation is not static. Just because WAMP on your local machine is setup to handle the memory usage does not mean that the install of php on your webserver is.

    I would suggest setting up a phpinfo file and compare your WAMP version of php to your hosted version. You should be able to quickly see the differences between the two. You can either setup your local WAMP install to match your hosted version or ask your webhost to change theirs.

    Your likely not going to have much luck on the hosted end if you are on a shared server but it's worth a shot.

    Hope that helps some.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度