Search code examples
phpmongodbamazon-web-serviceslithium

MongoDB crashing PHP on file save, 500 error; can retrieve file saved without issue


I was debugging a situation last night where running lighttpd and fastcgi was causing a 500 error when I was uploading files. A closer inspection showed that files were indeed being uploaded, and even saved to the Mongo database back-end, but it was still throwing a 500 error.

So today I switched over to apache, which we have had working on another system, yet the error still occurs, and instead an 'empty response' is presented. After a bit of investigation, I found that it appears to happen when saving the file to the Mongo database. My code is as follows:

$file = File::create();
$file->save(array('file'=>$data['file']));

It appears to be fine when creating the file, however on saving the file data, it seems to go into the database without issue, but I don't think it returns properly. Looking at the mongo logs, this appears after every database save:

run command my_db.$cmd { getlasterror: 1 }

So it would appear that the issue lies with MongoDB throwing some form of error when a file is saved to GridFS - has anyone come across such an issue before that might interfere with PHP causing it to essentially crash?

Thanks,

Dan

(Just to mention - I am using the Lithium PHP Framework, and the 64-bit version of MongoDB).

Update:

Just to be more thorough with whats happening, when running lighttpd I get this error on upload:

2012-03-24 13:14:42: (mod_fastcgi.c.2566) unexpected end-of-file (perhaps the fastcgi process died): pid: 21279 socket: unix:/tmp/php.socket-1 
2012-03-24 13:14:42: (mod_fastcgi.c.3354) response not received, request sent: 51519 on socket: unix:/tmp/php.socket-1 for /index.php?url=campaign/edit/4f6cf84ca8b057ee17000000, closing connection 

Saving data in Mongo goes without issue, it is just file uploads, the file size in question being 45K, so not even a large file.

This is running on AWS EC2, with PHP 5.3.10 and MongoDB 2.0.4

Further Update:

Just to try and make this as concise as possible, and get responses, what I have seemed to determine is that MongoDB is doing something 'after' the file is saved in it's database which is causing the PHP crashing issue.

Once the file has been saved, I can retrieve it without any issue whatsoever, it just seems on initially saving it to the database, it is causing PHP to crash and providing the 500 error.


Solution

  • I recently faced what could be the same problem:

    PHP was segfaulting in a variety of configurations; running PHP in FCGI mode under Lighttpd and under Apache, across x86 and x64 platforms.

    Turns out the culprit was the php-mongo driver (installed from PECL) - versions 1.2.8 and 1.2.9 would cause a segfault. I'm guessing this was after the save to GridFS was completed, as the data appeared to be stored correctly.

    Version 1.2.7 ran just fine.