• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.2 Fatal Error (Memory) when uploading / using GD


Active member
I've been seeing this recurring on our forum
ErrorException: Fatal Error: Out of memory (allocated 89653248) (tried to allocate 14140 bytes) - library/XenForo/Image/Gd.php:70
Generated By: UserName, 11 minutes ago
Stack Trace
#0 [internal function]: XenForo_Application::handleFatalError()
#1 {main}
Request State
array(3) {
  ["url"] => string(115) "http://www.talkphotography.co.uk/attachments/do-upload.json?hash=b8af0fasdfsdfsdfsdfsdfc8b41448b1047&content_type=post"
  ["_GET"] => array(2) {
    ["hash"] => string(32) "b8af0fasdfsdfsdfsdfsdfc8b41448b1047"
    ["content_type"] => string(4) "post"
  ["_POST"] => array(7) {
    ["Filename"] => string(12) "DSC_0111.JPG"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfSessionId"] => string(32) "c5e72fdaf9sfdsdfesdfsdfdff4bade3bd9dbf"
    ["_xfToken"] => string(8) "********"
    ["content_data"] => array(1) {
      ["thread_id"] => string(6) "538955"
    ["_xfResponseType"] => string(4) "json"
    ["Upload"] => string(12) "Submit Query"
It's always related to GD.php, and always referring to an upload / attachment.
PHP memory_limit is set to 164 (via php.ini, not script)

At first I was assuming the files being uploaded were way too big. (Xenforo seems to try to upload a file before it tells you it's too big, rather than read the file size first).

Any thoughts?

Edit : I forgot to mention, I have Development enabled via xenforo's config.php but only for my IP

Chris D

XenForo developer
Staff member
89,653,248 bytes is 85.5 MB.

That's pretty small. That may be down to a physical limit on your server.

If you go to http://www.talkphotography.co.uk/admin.php?tools/phpinfo search for "max_memory_limit". I'm guessing it will be around 85.5M. Talk with your host or server person about raising that limit. 128M - 256M are relatively typical values but equally you could go higher than that if you have the physical resources available.

It may be that size due to the physical limitations of your server, though, so raising it my lead to other errors (memory exhausted errors) or other performance related issues.

If that's the case, your only real option is to prevent images from being uploaded if they are beyond a certain size. You can restrict that in config.php:

$config['maxImageResizePixelCount'] = 10000000;
(You may need to experiment somewhat with the value)

This will prevent the server errors, but it still won't allow you to resize certain images.

Another option you may want to explore is switching to ImageMagick. It can be switched on in Admin CP > Options > Attachment Options, but it will need to be installed and enabled on your server before it becomes available as an option. It *may* allow larger images to be resized if ImageMagick can do so with a smaller memory footprint but even then, it's not likely to be a big difference.


Active member
Thanks Chris.

The memory_limit on PHP is set to 164M, so it should be enough, and it certainly shouldn't be falling over at 85M. this is what's puzzling me.
I dabbled with ImageMagick in a previous incarnation (when we were on vB), and it was a bit of a pain IIRC.

Chris D

XenForo developer
Staff member
The server could legitimately be out of memory due to other resources being used on the server. Usually the out of memory error indicates that, rather than the max_memory limit being hit. Either that, or something is overriding the limit set in PHP.ini.

Very recently I saw someone running Lightspeed and actually Lightspeed was limiting the memory with one of its own values rather than that set in php.ini. Is that a possibility?

Does the situation improve if you set the php.ini value higher? I suspect maybe not.

What is the memory usage on your server like, overall?


Active member
From my research this afternoon, I happened upon another with the same issue which was Litespeed (I wonder if it's the same discussion as the one you saw?).
That could very well be a possibility. I'll check Litespeed tomorrow.

Overall, memory usage is OK. It rarely causes us any problems, save for intensive admin-side tasks on the database (For example, when we were migrating over from vBulletin....however, it never dropped out, just needed a little more oomf to make it sing).

If I recall the two common memory errors are slightly different. The above denotes a lack of memory, and the other one reporting "Memory limit reached" (or some such).

Chris D

XenForo developer
Staff member
That's correct. Your error is indicating a lack of memory.

The other, and the issue I saw recently with Lightspeed, actually indicates the memory limit has been reached.

So raising the limit, and investigating Lightspeed configuration might not turn anything up in your case, but 85MB is still suspiciously low...


Active member
I've had a look in Litespeed, and the memory limit there is plenty.
However, with us running xCache, that does take up some of the available memory, so I've been tweaking.
I've dropped the xCache memory size to a better value, and we'll see how we go from here.
The server has 16GB in. I'm wary of increasing the memory available to PHP too much.

Edit : Thanks for the replies :)