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
Solved

Is there a way to use connection spooling in PHP?

Posted on 2014-02-10
6
290 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
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.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

839 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