Solved

Is there a way to use connection spooling in PHP?

Posted on 2014-02-10
6
292 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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 …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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.

679 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