MongoCursorException 'couldn't get response header'
Asked Answered
M

1

6

I am developing a website using PHP and mongodb. I access the mongodb with PECL-mongo, and have run into an annoyance. Every now and then, I get an error like this (I've anonymized the paths)

Fatal error: Uncaught exception 'MongoCursorException' with message 'couldn't get response header' in
    /PATH/index.php:38 Stack trace: #0 
    /PATH/index.php(38): MongoCursor->rewind() #1 
    /PATH/template.inc(29): get_sidebar() #2 
    /PATH/index.php(13): 
    require_once('PATH/...') #3 {main} thrown in PATH/index.php on line 38

According to the documentation, this means:

The driver could not fetch a reply header from the database, so it gave up. Check if the database is still up and the network is connected and try the query again.

But I know that the database is up because I am doing this locally on my own machine over loopback. No connection is made to the outside world.

Simply trying again often works. Is this a possibly a bug in PHP's driver for mongo? Could this be a "miscompile" issue (I compiled from source, but with very benign flags, -march=native -O2)?

Has anyone seen this before?

Searching around, I only see references to some stupid facebook game having the same error.

EDIT: I just downgraded my PECL driver to version 1.1.4 and so far, the problem seems have gone away. So this may simply be a bug in the 1.2.x series. If anyone can shed any light on it, that would be great.

EDIT: I am not doing anything complex here, the code that is having the issue litterally looks like this:

$m = new Mongo();
$collection = $m->my_db->collection;
$results = $collection->find(array("favorite"=>true))->limit(5);
Morgen answered 29/7, 2011 at 19:31 Comment(4)
So first note, you definitely want to catch the Exception. There may be a bug here, but without catching the Exception and logging data, it's hard to know what happened. Was there a failed Query? A failed Update/Insert/Delete? Are you cursoring through data when this happens?Prang
I'm running into the same issue as you. What solution did you end up implementing? I'm stuck with an ugly loop that checks for the exception =/Aeolic
I just downgraded my PECL driver to version 1.1.4. And it seems solid now.Morgen
FWIW, it looks like the new version of the PHP Mongo driver handles connections a little better (released yesterday): pecl.php.net/… This might solve your problem without having to run an old version of the driver.Quaternion
V
1

i solved this problem with get new version mogodb.dll you can see http://www.mongodb.org/display/DOCS/PHP+Language+Center

Vivia answered 4/4, 2012 at 14:8 Comment(1)
are you trying to say "problem"? what is a "pelbome", you've said it twice now.Morgen

© 2022 - 2024 — McMap. All rights reserved.