This is a discussion on simple questions but please answer me within the MySQL Database forums, part of the Database Forums category; Hi, I'm ending my website built with php+mysql. In a first moment I didn't want to use ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I'm ending my website built with php+mysql. In a first moment I didn't want to use mysql but with the help of some manuals and 'how to' I have learned the most important instructions for my necessities. Only in few articles I have found annotations on the importance to close the access to database after every login and interrogation. In some cases I've found simply this line at the end of the php page: mysql_close($db); in other cases: mysql_free_result($xx); mysql_close($db); in other cases any worry to close the access! In my website every page connects to database, so please could you explain me the importance to close the database connection for each page? What are the correct istructions to follow at the end of a webpage to correctly disconnect from a database? I speak a little english, i hope that you understand what i need. Thanks. Marco (Italy) |
|
|||
|
On 1 Feb, 10:53, "Mr.Orange" <freypnospa...@alice.it> wrote:
> Hi, > I'm ending my website built with php+mysql. > In a first moment I didn't want to use mysql but with the help of some > manuals and 'how to' I have learned the most important instructions for > my necessities. > Only in few articles I have found annotations on the importance to close > the access to database after every login and interrogation. > In some cases I've found simply this line at the end of the php page: > > mysql_close($db); > > in other cases: > > mysql_free_result($xx); > mysql_close($db); > > in other cases any worry to close the access! > > In my website every page connects to database, so please could you > explain me the importance to close the database connection for each page? > > What are the correct istructions to follow at the end of a webpage to > correctly disconnect from a database? > > I speak a little english, i hope that you understand what i need. > Thanks. > > Marco (Italy) A web page does not connect to a database. It is the php script that is running on the server that does that. As long as you are not opening persistent connections, the connection will be closed when the current set of php scripts finishes executing, so you do not need to worry about either mysql_free_result($xx); mysql_close($db); at the end of the scripts. |
|
|||
|
Thank you for the answer.
My worry is that if I don't close the connection with an appropriate command and there are more users simultaneously connected, there can be a loss of performance or deceleration of the server. I hope that you understand what I want to say. Marco > A web page does not connect to a database. It is the php script that > is running on the server that does that. > As long as you are not opening persistent connections, the connection > will be closed when the current set of php scripts finishes executing, > so you do not need to worry about either mysql_free_result($xx); > mysql_close($db); at the end of the scripts. |
|
|||
|
On 2 Feb, 11:51, "Mr.Orange" <freypnospa...@alice.it> wrote:
> Thank you for the answer. > My worry is that if I don't close the connection with an appropriate > command and there are more users simultaneously connected, there can be > a loss of performance or deceleration of the server. > I hope that you understand what I want to say. > > Marco > > > > > A web page does not connect to a database. It is the php script that > > is running on the server that does that. > > As long as you are not opening persistent connections, the connection > > will be closed when the current set of php scripts finishes executing, > > so you do not need to worry about either mysql_free_result($xx); > > mysql_close($db); at the end of the scripts.- Hide quoted text - > > - Show quoted text - Each "user" will be running a separate php session (not technically the correct term, but it'll do for now). Unless you have specifically opened persistent connections, each 'user' whole session (and their connections) will be shut down when apache (or whatever other server you are using) has finished delivering the page to the browser. |
|
|||
|
Mr.Orange wrote:
> Hi, > I'm ending my website built with php+mysql. > In a first moment I didn't want to use mysql but with the help of some > manuals and 'how to' I have learned the most important instructions for > my necessities. > Only in few articles I have found annotations on the importance to close > the access to database after every login and interrogation. > In some cases I've found simply this line at the end of the php page: > > mysql_close($db); > > in other cases: > > mysql_free_result($xx); > mysql_close($db); > > in other cases any worry to close the access! > > In my website every page connects to database, so please could you > explain me the importance to close the database connection for each page? > > What are the correct istructions to follow at the end of a webpage to > correctly disconnect from a database? > > I speak a little english, i hope that you understand what i need. > Thanks. > > Marco (Italy) > Although as others have indicated it's not necessary to close the connection or free the result, I prefer to do it myself rather than let the PHP interpreter do it. It may be a while before the interpreter gets around to cleaning up after the script ends, especially in a heavily loaded server (cleanup is generally not as important as executing the scripts themselves). I go by the rule that as soon as I'm done with a result, I free it. As soon as I'm completely done with the connection on that page, I close it. I find it's just generally a good programming practice to clean up after myself rather than let the system do it for me. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Hi Jerry,
and about the cleanup are enough these two lines to the end of each php page: mysql_free_result($xx); mysql_close($db); or there's some other command to add? Thanks. Marco > Although as others have indicated it's not necessary to close the > connection or free the result, I prefer to do it myself rather than let > the PHP interpreter do it. It may be a while before the interpreter > gets around to cleaning up after the script ends, especially in a > heavily loaded server (cleanup is generally not as important as > executing the scripts themselves). > > I go by the rule that as soon as I'm done with a result, I free it. As > soon as I'm completely done with the connection on that page, I close it. > > I find it's just generally a good programming practice to clean up after > myself rather than let the system do it for me. > |
|
|||
|
Mr.Orange wrote:
> Hi Jerry, > and about the cleanup are enough these two lines to the end of each php > page: > > mysql_free_result($xx); > mysql_close($db); > > > or there's some other command to add? > > Thanks. > Marco > > >> Although as others have indicated it's not necessary to close the >> connection or free the result, I prefer to do it myself rather than >> let the PHP interpreter do it. It may be a while before the >> interpreter gets around to cleaning up after the script ends, >> especially in a heavily loaded server (cleanup is generally not as >> important as executing the scripts themselves). >> >> I go by the rule that as soon as I'm done with a result, I free it. >> As soon as I'm completely done with the connection on that page, I >> close it. >> >> I find it's just generally a good programming practice to clean up >> after myself rather than let the system do it for me. >> That's all you need. But I don't necessarily put them at the end of the page. For instance, I free a result as soon as I'm done with it. So once I fetch the data and use it, I free the result immediately. And once I've completed my last request to the database, I close the connection immediately. Freeing the result immediately is more important, IMHO. Often times I'll have a page which makes several separate requests to MySQL. Freeing a result as soon as I'm done with it means I'm not unnecessarily tying up MySQL and other system resources. It's also easier to remember to free it if you're doing it right where you 're using the result set. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
> Jerry Stuckle ha scritto:
> That's all you need. But I don't necessarily put them at the end of the > page. For instance, I free a result as soon as I'm done with it. So > once I fetch the data and use it, I free the result immediately. And > once I've completed my last request to the database, I close the > connection immediately. ok, thanks to you too. ;-) Marco |