0

Does the phpdriver for mongoDB provide a feature for starting the connection on demand - only.

Maybe this can save some load, although persistent connection is already really fast.

However, if there is a chance to optimize the application, i'd try this, too.

The alternative, calling the function to connect only on demand seems to be a bit tricky and makes my source very redundant.

2
  • 1
    Why don't you write a class and call it when needed? When you instantiate it for the first time, then use persistent during that execution. You'll probably take longer to connect than to have it connected during all the execution. Commented Jul 5, 2012 at 14:24
  • 1
    looks like you can have it lazy connect: jira.mongodb.org/browse/… Commented Jul 5, 2012 at 15:32

2 Answers 2

1

The link H Hatfield posted addresses this question. Mongo::__construct() has a connect option that defaults to true, but you can specify false to delay the connection. The documentation isn't clear how lazy this is, as it only guarantees that the constructor will return without waiting for a connection to be established.

That said, you would be better off relying on persistent connections, which are being actively improved. I wouldn't be surprised if the lazy connection option was removed in a future major version of the driver.

Sign up to request clarification or add additional context in comments.

Comments

0

On the documentation page when initiating the Manager it says:

this constructor performs no I/O. Connections will be initialized on demand, when the first operation is executed. So this is actually what you need already.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.