PHP sin memoria, pero ¿por qué?

I have the following line of code, at the start of a function:


los $name contains the full server path to the non-publically accessible folder that contains the image, which is a 4.4MB JPG.

Normally when this problem has occurred, PHP needs more memory than is allocated to open the compressed image, and issuing a ini_set command to raise the member to 128MB solves the problem. However, in this case, it does not. I've tried raising to 256, 512 and 1024MB and still it comes back with an error:

Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 17152 bytes) in /imgprocess.php on line 83.

I've even tried using the (contraband!) -1 to allow unlimited memory, just to see if something was causing it to go sky high, but still no go.

I've tried a different image file incase it was a bad JPG, still no go.

¿Cómo se puede solucionar esto?

EDIT: I should add that PHP isn't in Safe Mode

preguntado el 10 de marzo de 12 a las 16:03

Out of interest, what size is the image (the image dimensiones, which will have a much better relation to the uncompressed in-memory size than the size of the lossily-compressed JPEG.) -

@Matt: Its 4288x2848 at 72dpi - Photoshop reports it as 34.9MB -

Allowed memory size of 262144 bytes something is wrong there. How and where are you setting the memory limit? -

The normal memory limit, set in PHP (and shown on phpinfo) is 32M. I've tried with the ini_set as the line directly before the imagecreatefromjpeg line. and still no go. Could there be a setting in PHP which prevents the ini_set from being actioned? -

the image needs about 50M memory to get created. (height*width*4). It is possible to prevent changing the memory limit when php is compiled. usually it is allowed with --enable-memory-limit but I guess some hosting providers might disable it -

1 Respuestas

Esto debería solucionar tu problema:

ini_set('memory_limit', '256m');

Por favor lee faq.using.shorthandbytes

Using "MB" is a wrong shorthand notation. ini_get() doesn't return normalized values most often it returns what it was set to.

respondido 30 mar '12, 21:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.