Solved

Is there a way to use connection spooling in PHP?

Posted on 2014-02-10
6
288 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
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This article discusses four methods for overlaying images in a container on a web page
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

815 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

8 Experts available now in Live!

Get 1:1 Help Now