Set connection timeout on Mongo PHP driver

1,986 views
Skip to first unread message

GVP

unread,
Mar 30, 2010, 8:14:35 PM3/30/10
to mongodb-user
It looks like the Mongo PHP driver *has* a timeout.

If I point the driver at a computer not running Mongo it fails. And
there is a MongoConnectionException with a timeout exception:
http://us.php.net/manual/en/class.mongoconnectionexception.php

However, I cannot find a way to set this timeout value using the PHP
driver.
The connect() method does not seem to support a timeout setting:
http://us.php.net/manual/en/mongo.connect.php

Is it possible to do such a configuration for a connection?

For context, I'm using Mongo in a very aggressive configuration. The
code is already built to "fail-over" to a default if the Mongo look-up
fails. So I'm looking to configure this connection timeout to
something under a second which is way lower than the current config.

Kristina Chodorow

unread,
Mar 31, 2010, 8:34:41 AM3/31/10
to mongod...@googlegroups.com
You can pass the timeout as an option to the constructor:

$m = new Mongo($host, array("timeout" => 1000));

...for a 1 second timeout, for example.  See http://us.php.net/manual/en/mongo.construct.php.



--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


GVP

unread,
Mar 31, 2010, 11:41:45 AM3/31/10
to mongodb-user
Awesome, thank you!

On Mar 31, 7:34 am, Kristina Chodorow <krist...@10gen.com> wrote:
> You can pass the timeout as an option to the constructor:
>
> $m = new Mongo($host, array("timeout" => 1000));
>

> ...for a 1 second timeout, for example.  Seehttp://us.php.net/manual/en/mongo.construct.php.


>
> On Tue, Mar 30, 2010 at 8:14 PM, GVP <gate...@gmail.com> wrote:
> > It looks like the Mongo PHP driver *has* a timeout.
>
> > If I point the driver at a computer not running Mongo it fails. And
> > there is a MongoConnectionException with a timeout exception:
> >http://us.php.net/manual/en/class.mongoconnectionexception.php
>
> > However, I cannot find a way to set this timeout value using the PHP
> > driver.
> > The connect() method does not seem to support a timeout setting:
> >http://us.php.net/manual/en/mongo.connect.php
>
> > Is it possible to do such a configuration for a connection?
>
> > For context, I'm using Mongo in a very aggressive configuration. The
> > code is already built to "fail-over" to a default if the Mongo look-up
> > fails. So I'm looking to configure this connection timeout to
> > something under a second which is way lower than the current config.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages