AJchandu
AJchandu

Reputation: 141

How to close MongoDB connection in PHP

I am using PHP mongoDB driver ver 1.1.8 My PHP code for establishing a connection to MongoDB goes like this

$conn=new MongoDB\Client("mongodb://localhost:27017");

But the problem is , each time a client refresh the page a new connection is established. Therefore i want to close the connection at the end of the PHP script.

Earlier i used to close a connection with this code

$conn->close();

But this is not working in the new PHP MongoDB drivers.

Upvotes: 4

Views: 8330

Answers (1)

Arijit
Arijit

Reputation: 1674

$conn->close(); is out dated and will not work with current driver.

The new driver is designed to leave connections open, and there is no method of turning that off.

Refer This

Upvotes: 5

Related Questions