The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Out of Memory with createimagefromjpeg

Discussion in 'General Discussion' started by paulkoan, Mar 17, 2009.

  1. paulkoan

    paulkoan Well-Known Member

    Joined:
    Nov 24, 2006
    Messages:
    80
    Likes Received:
    0
    Trophy Points:
    6
    Hello,

    I am using suphp, php 5.2.9

    When using the imagecreatefromjpeg function in php, my user is getting "Fatal error: Out of memory (allocated 20185088) (tried to allocate 13056 bytes)"

    So the script is running out of memory after 20MB. I get the same error with 64MB, 128MB and 256MB.

    Code:
    # php -i | grep memory
    memory_limit => 256M => 256M
    
    It seems like some other limit is coming into play here, but not one I can find.

    Any ideas?

    Thanks,

    Paul
     
    #1 paulkoan, Mar 17, 2009
    Last edited: Mar 17, 2009
  2. paulkoan

    paulkoan Well-Known Member

    Joined:
    Nov 24, 2006
    Messages:
    80
    Likes Received:
    0
    Trophy Points:
    6
    Interestingly, this error only occurs if the call is proceeded by a locale change:

    <?php
    setlocale(LC_ALL,'en_US.UTF-8');
    echo imagecreatefromjpeg("cimg1280.jpg");
    ?>

    As long as the image is sufficiently large (5MB in this instance), this will fail with the memory error if the locale is set, and won't if it isn't. Note that the locale setting is the default locale for this server, but but the imagecreate will fail if any locale call precedes it.

    Weird.
     
  3. wiresix

    wiresix Member

    Joined:
    Jun 1, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    seeing the same thing on a server for a customer of ours.... only 32M is the point where it bombs out and setting memory limits of 64, 128, 256M have no impact.
     
  4. paulkoan

    paulkoan Well-Known Member

    Joined:
    Nov 24, 2006
    Messages:
    80
    Likes Received:
    0
    Trophy Points:
    6
    I can trigger this issue without the setlocale, and with imagecreatetruecolor()

    So it is a process limit independent of the memory_limit setting by the look of it.

    I cannot see anything in rlimit that would cause this. Can we look for commonality?

    I tested on a another server running the same kernel and php version, same php compilation in easyapache, but the problem isn't present.

    The main differences are that for the one that doesn't work CSF is installed, and has postgres support in php.

    CSF has process memory limit alerting, but nothing that limits the memory a process can use.

    I can't see how postgres would make any difference. And I am getting this error from command-line php so apache and suphp are not influencing anything.
     
  5. remik

    remik Guest

    Same problem

    Hello.
    I have the same problem. It only applies to command line PHP (version 5.2.9). Changing php memory_limit variable doesn't help. It always hangs on 32MB.

    When running from Apache/suPHP the problem doesn't exist and memory_limit changes take affect.

    Anyone has an idea how to fix it? It looks like a different memory limit. I was checking ulimit and selinux, but found nothing. I have some customers with cron scripts, which need extra memory to run and this problem blocks them.

    Looking forward for a quick reply.

    Remik
     
  6. remik

    remik Guest

    Hello.
    I've found out where the problem is. The ulimit is set per user and is lower than PHP's limit. This is the setting of ulimit:

    ulimit -a
    core file size (blocks, -c) 200000
    data seg size (kbytes, -d) 200000
    scheduling priority (-e) 0
    file size (blocks, -f) unlimited
    pending signals (-i) 26623
    max locked memory (kbytes, -l) 32
    max memory size (kbytes, -m) 200000
    open files (-n) 100
    pipe size (512 bytes, -p) 8
    POSIX message queues (bytes, -q) 819200
    real-time priority (-r) 0
    stack size (kbytes, -s) 8192
    cpu time (seconds, -t) unlimited
    max user processes (-u) 20
    virtual memory (kbytes, -v) 200000
    file locks (-x) unlimited

    Root's ulimit is higher. I tried running as root and than doing su to my user. The php scripts worked fine and were respecting php's memory_limit.

    The problem is I don't know where to change per user's ulimit and which variable is responsible for blocking php's memory_limit. I tried changing the ulimit settings in /etc/bashrc and /etc/profile, but it didn't help. I am using Cent OS.

    Any ideas where to find per using ulimit settings?


    Remik
     
  7. paulkoan

    paulkoan Well-Known Member

    Joined:
    Nov 24, 2006
    Messages:
    80
    Likes Received:
    0
    Trophy Points:
    6
    Actually, after a lot of messing around with ulimit settings and getting nowhere, I re-ran the Memory Usage Restrictions tool in Apache Configuration, and with an increase there, the problem went away.
     
  8. remik

    remik Guest

    The apache memory limit didn't help, because I am running my applications from command line (PHP CLI).

    I managed to fix the problem, but it's not very nice.

    The idea is I had to put this line into /etc/security/limits.conf:
    username hard core 0

    This changes ulimit for this user called 'username' to:
    core file size (blocks, -c) 0
    virtual memory (kbytes, -v) unlimited

    Virtual memory is unlimited and the user may use as much memory as PHP allows him to :)

    I than changed a bit my /etc/bashrc and /etc/profile to set a limit for these users (ulimit -v), which is high enough for my PHP applications.

    I have no idea why setting core file size limit to 0 automatically turns off the virtual memory limit, but it works :) I tried setting core file size limit to unlimited, but doesn't take any effect :/


    Remik
     
  9. karikas

    karikas Member

    Joined:
    Mar 8, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Thank you, thank you, thank you remick - your solution brought me back from the edge of insanity. I couldn't figure out why, no matter what I did to my php configuration, I couldn't use more than 128M of memory in the command line. This worked perfectly!
    - Mike
     
  10. webstyler

    webstyler Well-Known Member

    Joined:
    Nov 20, 2003
    Messages:
    432
    Likes Received:
    0
    Trophy Points:
    16
    Hi

    there aren't more cleaned way to hank this limit ??

    thanks
     
  11. SelyukCorp

    SelyukCorp Registered

    Joined:
    Mar 9, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    try disable apache mod_security...
     
Loading...

Share This Page