zendframework / zend-expressive

PSR-15 middleware in minutes!
BSD 3-Clause "New" or "Revised" License
711 stars 197 forks source link

Exhausted memory when uploading files #164

Closed acelaya closed 9 years ago

acelaya commented 9 years ago

I'm experiencing this error from time to time on an application that I'm developing with Expressive. Sometimes when I try to upload a file I get this Fatal error.

[Mon Oct 19 23:08:17.670338 2015] [:error] [pid 5435] [client 127.0.0.1:43546] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 140367508812784 bytes) in Unknown on line 0, referer: http://foobar.local

I've seen it both in apache's log and by using the PHP's built-in web server, but I'm not sure what's causing it.

What I'm doing is getting the uploaded files from the request (usually just a small file, from 50 to 300 Kb), and parsing them to array in order to be able to validate them with a Zend\InputFilter\FileInput object. This is how my parsing method looks like:

public static function uploadedFileToArray(UploadedFileInterface $uploadedFile)
{
    return [
        'tmp_name' => $uploadedFile->getStream()->getMetadata('uri'),
        'name' => $uploadedFile->getClientFilename(),
        'type' => $uploadedFile->getClientMediaType(),
        'size' => $uploadedFile->getSize(),
        'error' => $uploadedFile->getError()
    ];
}

The FileInput has just one Zend\Validator\File\IsImage validator. If I comment the $inputFilter->isValid() call, then the file is properly uploaded and the error is not produced. I'm not sure if it has something to do with the way the stream is handled in the Zend\Diactoros\UploadedFile object, that grows too much for some reason.

acelaya commented 9 years ago

I'm closing this because I'm almost sure it has nothing to do with Expressive or Diactoros.

gabrielsch commented 8 years ago

@acelaya I'm getting the same problem, did you solve it?

acelaya commented 8 years ago

I wasn't able to take the time to investigate it, so no, I didn't.

Alejandro Celaya Alastrué El 8/3/2016 19:03, "Gabriel Schmitt" notifications@github.com escribió:

@acelaya https://github.com/acelaya I'm getting the same problem, did you solve it?

— Reply to this email directly or view it on GitHub https://github.com/zendframework/zend-expressive/issues/164#issuecomment-193894048 .

Maks3w commented 8 years ago

https://github.com/zendframework/zf2/issues/7629#issuecomment-176836612

acelaya commented 8 years ago

Thanks @Maks3w