Solved

Is there a way to use connection spooling in PHP?

Posted on 2014-02-10
6
284 Views
Last Modified: 2014-02-10
How do PHP developers handle database transactions, generally? Do they create a connection then close the connection after every transaction? In Java, that's known to be a resource-intensive and inefficient way to handle database transactions, but I am not able to find any good articles on PHP connection pooling.

I'm just a noob in PHP, so I am asking out of trying to get a feel how the PHP industry handles this.

Thanks.
0
Comment
Question by:elepil
  • 3
  • 3
6 Comments
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Any open connections will be automatically closed when the page has finished processing.
There is no connection pooling.
0
 

Author Comment

by:elepil
Comment Utility
Just to confirm, so you're saying I don't even have to deliberately close the connection?

Part of my asking these questions is to get an idea of how the PHP culture thinks. If I apply for a PHP job, I don't want a potential boss to tell me, "What? You don't close your connections??" So pardon me if my questions sound stupid, I just feel I should ask them regardless.

Thanks.
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
Correct, they are automatically closed.  The only time you may need to manually close them is if it was likely the db connection limit might be reached.

http://www.php.net/manual/en/pdo.connections.php

If you want persistent connections
http://www.php.net/manual/en/mysqli.quickstart.connections.php
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:elepil
Comment Utility
Excuse me, but what you just said sounds contradictory.

You said the connection is automatically closed when the page has finished processing.

Then you said the only time you need to close it is if a db connection limit might be reached.

But if a connection is automatically closed when the page finishes processing, why would there even be a danger of reaching the db connection limit?
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Because you could have a connection open and then your code which may take a while to execute, repeat a few hundred times with different visitors and you have multiple open connections that are not doing anything.  
Or you have 500 people hit your site at the same time.
This would be very much the case on shared hosting where you would likely have a small limit on the number of connections.
Default is 151 connections on Apache.
0
 

Author Closing Comment

by:elepil
Comment Utility
Okay, I understand. Thanks for your help.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now