WEB Fatal error: Out of memory (allocated 524288) (tried to allocate 311296 bytes)

Discussion in 'OT Technology' started by Ricky, Jan 22, 2009.

  1. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    its pointing to this line

    Code:
                    $_post_body .= "Content-Disposition: form-data; name=\"$key\"; filename=\"{$file_info['name']}\"\r\n";
    
    :o

    Only happens randomly. Its weird though cause i was able to hold like 30 concurrent users all day today. I was messing around with the layout and it somehow stopped loading pages.

    I reverted to several backups and it was still fucked up. Someone suggested stopped the iptables or something, which i did and i believed it fixed it temp. In the end i just formated the OS and started over, but now im getting that error :o

    EDIT:


    +

    Here's my current setup

    Code:
    here's my current setup btw
    
    [QUOTE]#
    # Server-Pool Management (MPM specific)
    # 
    
    #
    # PidFile: The file in which the server should record its process
    # identification number when it starts.
    #
    # Note that this is the default PidFile for most MPMs.
    #
    <IfModule !mpm_netware_module>
        PidFile logs/httpd.pid
    </IfModule>
    
    #
    # The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
    #
    <IfModule !mpm_winnt_module>
    <IfModule !mpm_netware_module>
    LockFile logs/accept.lock
    </IfModule>
    </IfModule>
    
    #
    # Only one of the below sections will be relevant on your
    # installed httpd.  Use "apachectl -l" to find out the
    # active mpm.
    #
    
    # prefork MPM
    # StartServers: number of server processes to start
    # MinSpareServers: minimum number of server processes which are kept spare
    # MaxSpareServers: maximum number of server processes which are kept spare
    # MaxClients: maximum number of server processes allowed to start
    # MaxRequestsPerChild: maximum number of requests a server process serves
    <IfModule mpm_prefork_module>
        StartServers          5
        MinSpareServers       5
        MaxSpareServers      10
        MaxClients          150
        MaxRequestsPerChild   0
    </IfModule>
    
    # worker MPM
    # StartServers: initial number of server processes to start
    # MaxClients: maximum number of simultaneous client connections
    # MinSpareThreads: minimum number of worker threads which are kept spare
    # MaxSpareThreads: maximum number of worker threads which are kept spare
    # ThreadsPerChild: constant number of worker threads in each server process
    # MaxRequestsPerChild: maximum number of requests a server process serves
    <IfModule mpm_worker_module>
        StartServers          2
        MaxClients          150
        MinSpareThreads      25
        MaxSpareThreads      75 
        ThreadsPerChild      25
        MaxRequestsPerChild   0
    </IfModule>
    
    # WinNT MPM
    # ThreadsPerChild: constant number of worker threads in the server process
    # MaxRequestsPerChild: maximum  number of requests a server process serves
    <IfModule mpm_winnt_module>
        ThreadsPerChild     250
        MaxRequestsPerChild   0
    </IfModule>
    
    # BeOS MPM
    # StartThreads: how many threads do we initially spawn?
    # MaxClients:   max number of threads we can have (1 thread == 1 client)
    # MaxRequestsPerThread: maximum number of requests each thread will process
    <IfModule mpm_beos_module>
        StartThreads            10
        MaxClients              50
        MaxRequestsPerThread 10000
    </IfModule>
    
    # NetWare MPM
    # ThreadStackSize: Stack size allocated for each worker thread
    # StartThreads: Number of worker threads launched at server startup
    # MinSpareThreads: Minimum number of idle threads, to handle request spikes
    # MaxSpareThreads: Maximum number of idle threads
    # MaxThreads: Maximum number of worker threads alive at the same time
    # MaxRequestsPerChild: Maximum  number of requests a thread serves. It is 
    #                      recommended that the default value of 0 be set for this
    #                      directive on NetWare.  This will allow the thread to 
    #                      continue to service requests indefinitely.                          
    <IfModule mpm_netware_module>
        ThreadStackSize      65536
        StartThreads           250
        MinSpareThreads         25
        MaxSpareThreads        250
        MaxThreads            1000
        MaxRequestsPerChild      0
        MaxMemFree             100
    </IfModule>
    
    # OS/2 MPM
    # StartServers: Number of server processes to maintain
    # MinSpareThreads: Minimum number of idle threads per process, 
    #                  to handle request spikes
    # MaxSpareThreads: Maximum number of idle threads per process
    # MaxRequestsPerChild: Maximum number of connections per server process
    <IfModule mpm_mpmt_os2_module>
        StartServers           2
        MinSpareThreads        5
        MaxSpareThreads       10
        MaxRequestsPerChild    0
    </IfModule>
    [/QUOTE]
    

    HALP
     
    Last edited: Jan 22, 2009
  2. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Umm pretty sure that's just a PHP process out of memory error, so not sure why you're reformatting the OS >_<

    Is that script manipulating images or uploads or reasonably large binary files? They will be eating memory, so you need to optimize that or just increase the available ram for the PHP process.
     
  3. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    yeah it is manipulating images etc.

    Any tips for optimizing it and allowing more ram? Would that be in the php.ini or something :o

    im a complete newb at this :o

    Im on fedora 10 running the latest release of xampp
     
  4. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    i just doubled up the ram on my server and am stillg etting it :o

    Fatal error: Out of memory (allocated 524288) (tried to allocate 311296 bytes) in /opt/lampp/htdocs/index.php on line 642
     
  5. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    yes, there is a setting in php.ini that limits how much memory can be allocated towards a script.

    memory_limit i think.

    you can use ini_set() to increase it for the duration of the script.
     
  6. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    i up'd it form 8mbs to 16 and im still getting the same error :o
     
  7. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    i just looked and mine was default at 32M. if you're doing some heavy image processing you might need a lot more than that i would assume.
     
  8. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    Hello,

    The httpd process spawned several child processes, enough to affect the
    performance of your server. You can optimize httpd.conf to adjust how
    many of these children get spawned.

    Good day,
    vpslink.com - Support
     
  9. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    I have no idea where in that file i should be looking

    anyways im off to sleep. i have classes tommorow but please feel free to help out if you have any time :o
     
  10. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Ignore the vpslinks asses for now.

    Code:
    <?php
    
    $initial = ini_get('memory_limit');
    ini_set('memory_limit', '50M');
    $result = ini_get('memory_limit');
    
    print "<p>Memory Limit: $initial</p>";
    print "<p>New Memory Limit: $result</p>";
    
    ?>
    
    Just try the above to check and make sure what the limit is set to, and if you can change it dynamically.

    Ram is cheap and there's a lot of it available so don't be afraid to up it to something a lot more substantial dynamically for that script.

    You can estimate how many bytes an image will take up in memory by calculating width * height * 4.

    e.g. a 7.1 MegaPixel shot will take up at least 27MB
     
  11. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    the thing is, its not really manipulating images but websites itself

    its a proxy, so basially the whole code is somewhat being rewritten as the site is processed.

    As soon as i can get my shit to log me in i'll bypass it for now. thanks
     
  12. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    i set that but now im getting the error immediatly when loading the page, after restarting the server. Before it was coming up every so often.

    kinda weird

    edit: got it to work for now. it wasnt restarting properly.

    Any idea about the child spawning? I googled it up and theres a bunch of stuff i can change but i have no idea what kind of figures i should be looking at
     
    Last edited: Jan 22, 2009
  13. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    here's my current setup btw

     
  14. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    You might need to get vpslink.com to elaborate as it's not clear to me exactly what they're suggesting.

    Is that an automated message? The main thing I can think of is that you don't have enough memory to support the amount of spawned child processes, and this could also impact your PHP scripts like you've been seeing.

    I'm assuming you're paying them money, so make them help you out!
     
  15. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    Hello,

    The server runs out of memory approximately 15 minutes after it starts
    from a reboot. I suggest optimizing the services or look into
    reinstalling the OS because its possible the server could have been
    compromised.

    Good day,
    vpslink.com - Support
     
  16. tryfuhl

    tryfuhl New Member

    Joined:
    Oct 4, 2003
    Messages:
    75,450
    Likes Received:
    0
    Location:
    MD/DC Metro
    lol
     
  17. Karnejj

    Karnejj “A true conservative is one who can't see any diff OT Supporter

    Joined:
    Jan 9, 2008
    Messages:
    35,585
    Likes Received:
    0
    Location:
    UPGRADED USA Shutdown Today:8 derps
    Sounds like some runaway process.....

    Did you implement the code to change the memory limits?
     
  18. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    yeah i did

    changed it to 50M like suggested
     
  19. Karnejj

    Karnejj “A true conservative is one who can't see any diff OT Supporter

    Joined:
    Jan 9, 2008
    Messages:
    35,585
    Likes Received:
    0
    Location:
    UPGRADED USA Shutdown Today:8 derps
    k ... before the line where it crashes, put in something like this to keep resizing as needed.

    $prev = ini_get('memory_limit');
    $presize= preg_replace("@\D@", "", $prev);
    $newsize = $presize + 1;
    if ($newsize <= 1)
    {
    print "Problem resizing";
    }
    else
    {
    ini_set('memory_limit', $newsize."M");
    }
    It is kinda dependent on the memory size being set in units of "M" (megabytes), but that shouldn't really be a big deal.

    Now ... either your code will work, or it'll consume your system resources and crash. Either way, you should end up knowing whether you need a new approach or not.
     
    Last edited: Jan 27, 2009
  20. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Before you focus on your script, you should monitor your web server error and access logs while watching processes with top, and see what's happening to get that memory up.

    If you can narrow it down to your script, you can then focus on that.

    And rather than dynamically increasing the allocated memory which will just worsen the problem, regular poll memory_get_usage() at different lines of your script to see how much it's increasing by at various stages.

    I don't see why your helpdesk can't help you with that, especially as they have the power to closely monitor your system, while we can only guess and offer suggestions.
     
  21. Karnejj

    Karnejj “A true conservative is one who can't see any diff OT Supporter

    Joined:
    Jan 9, 2008
    Messages:
    35,585
    Likes Received:
    0
    Location:
    UPGRADED USA Shutdown Today:8 derps
    The only known problem as of now is that his script is exceeding the memory allocated for PHP scripts. Pretty clearly, increasing the memory allocation doesn't worsen that problem.

    The suggested dynamic allocation is not any final solution, only an attempt to discern if any amount of memory allocation would work or whether he's just spinning his wheels and needs a new approach altogether.
     
  22. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Both our solutions are reasonably similar. Your way will eventually hit a memory limit, and then you'll still have to find out exactly what is requiring this memory.

    My method, I want him to skip right to finding out exactly what function call or resource is demanding the memory, so that can be further investigated.

    Also I'm starting to suspect that there might be something else eating RAM meaning there's not enough for PHP. Not really sure how much RAM he gets allocated in the first place, and what else he has running on there.
     
  23. vincentfasho

    vincentfasho New Member

    Joined:
    Jun 17, 2004
    Messages:
    1,322
    Likes Received:
    0
    Location:
    Houston
    If you're simply running out of memory, try to modify your global php.ini

    Usually located at /usr/local/lib/php.ini, then search the file for memory_limit

    Also make a phpinfo page

    Code:
    <? phpinfo(); ?> 
    That will let you know what php.ini is using, whether it be in your user directory or the global php.ini. Usually you don't have to increase the ram of a box because normal memory limits are set at 64mb maybe even 128, but thats pretty far out there.. Might want to consider modiying your max execution time as well.
     
  24. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Why read the thread, when you can just jump in with your 2c!
     
  25. vincentfasho

    vincentfasho New Member

    Joined:
    Jun 17, 2004
    Messages:
    1,322
    Likes Received:
    0
    Location:
    Houston
    because i can do that you arrogant cunt =D
     

Share This Page