Solved

Is there a way to use connection spooling in PHP?

Posted on 2014-02-10
6
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 58

Expert Comment

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

Author Comment

by:elepil
ID: 39848853
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
ID: 39848866
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:elepil
ID: 39848880
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
ID: 39848891
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
ID: 39848897
Okay, I understand. Thanks for your help.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change Wording in Wordpress Plugin 4 39
PHP-MSSQL 2016 connection requirements for Windows 2012 29 80
How to close my php post page. 3 41
How do I add date to text file name 15 28
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 i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 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