Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8546681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:05:26+00:00 2026-06-11T13:05:26+00:00

For the relevant part of our server stack, we’re running: NGINX 1.2.3 PHP-FPM 5.3.10

  • 0

For the relevant part of our server stack, we’re running:

  • NGINX 1.2.3
  • PHP-FPM 5.3.10 with PECL mongo 1.2.12
  • MongoDB 2.0.7
  • CentOS 6.2

We’re getting some strange, but predictable behavior when the MongoDB server goes away (crashes, gets killed, etc). Even with a try/catch block around the connection code, i.e:

try
{
    $mdb = new Mongo('mongodb://localhost:27017');
}
catch (MongoConnectionException $e)
{
    die( $e->getMessage() );
}

$db = $mdb->selectDB('collection_name');

Depending on which PHP-FPM workers have connected to mongo already, the connection state is cached, causing further exceptions to go unhandled, because the $mdb connection handler can’t be used. The troubling thing is that the try does not consistently fail for a considerable amount of time, up to 15 minutes later, when — I assume — the php-fpm processes die/respawn.

Essentially, the behavior is that when you hit a worker that hasn’t connected to mongo yet, you get the die message above, and when you connect to a worker that has, you get an unhandled exception from $mdb->selectDB('collection_name'); because catch does not run.

When PHP is a single process, i.e. via Apache with mod_php, this behavior does not occur. Just for posterity, going back to Apache/mod_php is not an option for us at this time.

Is there a way to fix this behavior? I don’t want the connection state to be inconsistent between different php-fpm processes.

Edit:
While I wait for the driver to be fixed in this regard, my current workaround is to do a quick polling to determine if the driver can handle requests and then load or not load the MongoDB library/run queries if it can’t connect/query:

try
{
    // connect
    $mongo = new Mongo("mongodb://localhost:27017");

    // try to do anything with connection handle
    try
    {
        $mongo->YOUR_DB->YOUR_COLLECTION->findOne();
        $mongo->close();
        define('MONGO_STATE', TRUE);
    }
    catch(MongoCursorException $e)
    {
        $mongo->close();
        error_log('Error connecting to MongoDB: ' . $e->getMessage() );
        define('MONGO_STATE', FALSE);
    }
}
catch(MongoConnectionException $e)
{
    error_log('Error connecting to MongoDB: ' . $e->getMessage() );
    define('MONGO_STATE', FALSE);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:05:27+00:00Added an answer on June 11, 2026 at 1:05 pm

    The PHP mongo driver connectivity code is getting a big overhaul in the 1.3 release, currently in beta2 as of writing this. Based on your description, your issues may be resolved by the fixes for:

    https://jira.mongodb.org/browse/PHP-158

    https://jira.mongodb.org/browse/PHP-465

    Once it is released you will be able to see the full list of fixes here:

    https://jira.mongodb.org/browse/PHP/fixforversion/10499

    Or, alternatively on the PECL site. If you can test 1.3 and confirm that your issues are still present then I’m sure the driver devs would love to hear from you before the 1.3.0 release, especially if it is easily reproducible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running an IIS 7 windows server and a relevant part of my phpinfo's
Here's the relevant part of my ~/.ipython/ipy_user_conf.py file on a system running IPython .10.1:
Here's the relevant part of the Dice class: import java.util.*; class Dice { String
A major part of our work is creating and manipulating certain XML files, for
Here is the most relevant part of my database schema: create table TEST (
I'm trying to parse values with ANTLR. Here's the relevant part of my grammar:
The relevant part of the code: pk = int(pk) logging.info('pk: %r :: %s', pk,
I have class where the relevant part looks like class C { void Method<T>(SomeClass<T>
Here is relevant part of HTML code: < a id=interest name=interest href=# value=1 onclick=alert(this.value);>Interested<
We are developing several web applications to run on our own server that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.