Bug #71093 [Opn->Nab]: GD: Very high memory consumption with bundled library 2.1.0
| From: | pajoye@php.net | Date: | Sat, 12 Dec 2015 10:31:41 +0000 |
| Subject: | Bug #71093 [Opn->Nab]: GD: Very high memory consumption with bundled library 2.1.0 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197827@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71093&edit=1
ID: 71093
Updated by: pajoye@php.net
Reported by: jeep dot gaudreau at gmail dot com
Summary: GD: Very high memory consumption with bundled
library 2.1.0
-Status: Open
+Status: Not a bug
Type: Bug
Package: GD related
Operating System: Fedora 23
PHP Version: 5.6.16
Block user comment: N
Private report: N
New Comment:
Both bundled or system library will use the same amount of memory (as explained by Danak).
The bundled library uses the php memory management system while the system library does not.
It explains why get_memory_usage will show different values. Use a ps or other to see how much
memory is used by the php process and you will see the actual usage (php and all libs).
Previous Comments:
------------------------------------------------------------------------
[2015-12-12 03:24:17] danack@php.net
The linked image has dimensions of 16,313 x 3,621. With 4 bytes per pixel, this comes to 236,277,492
bytes of image data.
This is much bigger than the jpeg file size, because the JPEG file holds compressed data, whereas GD
has to decompress the data to be able to use it.
I'm not sure what is happening to make it look like "not more than a few KB" of
memory is being used in other scenarios, but it sounds like that something is misleading you, as it
is normal for large amounts of memory to be used, when a large image is being converted.
------------------------------------------------------------------------
[2015-12-11 14:38:21] jeep dot gaudreau at gmail dot com
Description:
------------
I found out that the GD library bundled with PHP 5.6.16 (version 2.1.0) is using a lot of memory
when calling functions "imagecreatefromjpeg" or "imagecreatefromstring" on JPEG
files.
A JPEG file of about 4MB can generate up to 300MB of memory while it take not more than a few KB
when using the OS package of GD version 2.1.1.
I can also reproduce the bug on RHEL6.5
Maybe the solution would only be to upgrade the bundled PHP GD library to 2.1.1.
Here's the GD info when memory consumption is very high :
GD Support enabled
GD Version bundled (2.1.0 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.6.0
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.6.19
WBMP Support enabled
XPM Support enabled
libXpm Version 30411
XBM Support enabled
WebP Support enabled
GD Support enabled
Here's the GD info when memory consumption is low :
GD headers Version 2.1.1
GD library Version 2.1.1
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.6.0
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.6.19
WBMP Support enabled
XPM Support enabled
libXpm Version 30411
XBM Support enabled
WebP Support enabled
Test script:
---------------
Very easy to reproduce:
* Create the following PHP script:
<?php
$path = 'img.jpg';
//$image = imagecreatefromjpeg($path);
$image = imagecreatefromstring(file_get_contents($path));
var_dump(memory_get_usage());
* Execute with the following JPEG image: https://drive.google.com/open?id=0B0H8CbGn160eMHg3cGZrSmtzRTA
You should have very high memory usage with bundled library 2.1.0
You should have very low memory usage with OS package GD version 2.1.1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71093&edit=1