Monday, September 3, 2012

PHP 5.4 upload progress error

   I discovered something today after several days of baffling code output, obscure error messages, and altogether confusion on what could be the problem. It all started with simple file upload script that would, seemingly randomly, return a 502 response from nginx. A look into the nginx log showed [error] 18646#0: *1225 recv() failed (104: Connection reset by peer) while reading response header from upstream, ..."
which basically equates to it being PHP's my PHP script's fault. Apparently, PHP couldn't process the request, so it just refused it.

   The next logical step seemed to be to take a peak at the PHP log. Which helpfully read "PHP Warning:  Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0". This warning was confusing to me since I wouldn't expect a "Warning" to cause a connection reset error as above. But I digress.

   Thinking it was a problem with my (very simple) session handler class, I combed through each line looking for anything that could cause an invalid session id. But everything session related had worked just fine until I tried to upload a file with an HTML form. Specifically, multiple files. Also, the problem had risen after some unfinished experimentation with PHP 5.4's "upload progress" feature. Scouring Google finally lead me to a clue from [nihaopaul at gmail dot com's] on php.net mentioning the importance of the field order, simply stating that "otherwise you wont get any updates". It turns out that the required session.upload_progress.name hidden field should probably MUST be BEFORE any file inputs or the file upload begins before the upload session can start.

So if you find yourself with this cryptic log warning, hopefully you've stumbled across this page and found the information helpful.


The mentioned software versions are Nginx 1.2.3 / PHP 5.4.5

No comments:

Post a Comment