473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Database server auto-close

I just wondered if someone could clarify... I have a a script connecting
with mysql_connect and in an include at end of page mysql_close

If they script terminates before end of page ie. with an exit() or maybe
trigger_error(), does php always disconnect the open'ed connection?

I ask because PHP manual says yes, but I've seen some comments relating
to PHP 4 saying it doesn't.

Please can you tell me your experiences?
Apr 30 '07 #1
3 2024
On Apr 30, 10:58 am, Tyno Gendo <you@localhostwrote:
I just wondered if someone could clarify... I have a a script connecting
with mysql_connect and in an include at end of page mysql_close

If they script terminates before end of page ie. with an exit() or maybe
trigger_error(), does php always disconnect the open'ed connection?

I ask because PHP manual says yes, but I've seen some comments relating
to PHP 4 saying it doesn't.

Please can you tell me your experiences?
Yes, that applies to all resource handles opened during execution--
database connections included. It's actually just one instance of a
general phenomenon in PHP. When the last variable pointing to the
resource handle goes out of scope, the handle is closed. For example,
in the following function:

function log($s) {
$f = fopen("log.txt", "wb");
fwrite($f, $s);
}

the file will be closed automatically when the function returns, as $f
goes out of scope.

And the following is perfectly okay:

if(mysql_connect( ... )) {
}

Since the handle returned isn't saved, the connection will be closed
immediately.

When a script terminates--one way or another--all variables within it
are destroyed, so all resource handles will be closed.

Persistent connections are a different story--you can only close these
by terminating the web server.

As a side note: Don't wait till the end of the page before you close
the database connection. That's a recipe for "Too many connections"
errors. Read the necessary data from the database then close the
connection before you output to the client.

Apr 30 '07 #2
Chung Leong wrote:
As a side note: Don't wait till the end of the page before you close
the database connection. That's a recipe for "Too many connections"
errors. Read the necessary data from the database then close the
connection before you output to the client.
Could you expand on that?
I can't think of a way that closing at the end would do that.
Apr 30 '07 #3
On Apr 30, 8:08 pm, Sanders Kaufman <b...@kaufman.netwrote:
Chung Leong wrote:
As a side note: Don't wait till the end of the page before you close
the database connection. That's a recipe for "Too many connections"
errors. Read the necessary data from the database then close the
connection before you output to the client.

Could you expand on that?
I can't think of a way that closing at the end would do that.
Well, it's not that hard to understand. It takes time for the page to
get sent to the client. Generally it's a lot longer than the time it
takes to retrieve data from the database. A query might take 100
millisec. Transferring a HTML page could conceivably take over 10
seconds. Holding onto the connection til the end of the page means
more concurrent connection there needs to be.

Apr 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ken | last post by:
Need help on the Auto Number or Identity Seed on the Oracle Database I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER"...
5
by: Brian | last post by:
I have a small application with 2 forms where the user logs into the system, then the form recordsource randomly pulls up an account ID. The application is basically an electronic tic sheet and...
6
by: alanknipmeyer | last post by:
Hi, I`m in the process of migrating a Access 2002 (Run in 2000 mode) from Windows 98 to Win2K Server. It is a shared resource via a file share on the 98 Server. Client systems are Win98 with the...
6
by: Helmut | last post by:
Hello, I am Helmut, my database has a Frontend of 15.4 MB which cause Acc2K to corruption: Limit is 12.5 MB. Service Pack 3. On three different PCs with 256, 512 and 1.000 MB RAM. All on W2K,...
3
by: Freddie | last post by:
hi, i try to get the asp.net 2.0 security controls to work with SQL Server 2005 Dev RTM, this is my connetion string in mashine.config <connectionStrings> <add name="LocalSqlServer"...
0
by: Jonathan Wood | last post by:
I seem to be having errors creating and accessing an SQL database. Unfortunatley, I am brand new to SQL setup and administration issues so this really is not my area of expertise. I know I had...
2
by: Patrick F | last post by:
Hi, i have SQL Server 2005 and a database set that is called, myCompany the problem is that i cant connect from my page to it, here is from the web.config: ( i have got this connectionstring from...
1
by: Mrozik | last post by:
Hi! I have Web Application with forms authentication. Data and security model resides in Oracle database. I have 'login' page with MS 'Login' control. In my LoggingIn event for debug purposes I...
3
by: weird0 | last post by:
This is the exception that I get when i create a webserivce obj and call. The error comes on the webmethod call, when it opens a connection to the db. How do I fix it? What is the solution to...
36
by: pearl146 | last post by:
Hi, I have some database files (.MDF, .LDF,...) on the server. When I try to delete them, the warning "Cannot delete file: There has been a sharing violation. The source or destination file may...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.