Languages :: PHP :: PHP Cleanup... |
|||
| By: coders4hire |
Date: 02/08/2003 00:00:00 |
Points: 100 | Status: Answered Quality : Excellent |
|
I have ensured in my code that I close all db connections when I'm done. I'm working with a ton of arrays and variables on my application. Is there anything I need to do to clean those up after the app is finished? Is there some common PHP protocol to keep in mind when writing an application? Thanks, Doug |
|||
| By: wtgee | Date: 03/08/2003 05:55:00 | Type : Comment |
|
| PHP will clean up all variables and arrays and all that good stuff. You want to make sure you close database and file handles, but don't worry about the varialbes and arrays. |
|||
| By: VGR | Date: 03/08/2003 19:05:00 | Type : Assist |
|
| agree. You can even leave out the connection to the DB... Only closing the textfiles fopen()-ed is good practice |
|||
| By: coders4hire | Date: 03/08/2003 23:19:00 | Type : Comment |
|
| How about session variables? I have set them to unset when the app is completed - HOWEVER, if a user quits half way into the app - what happens? Thanks! You guys have answered a ton of my questions... I basically built a full database app in the last 2 weeks with your help! I'm sure it could use some additional cleanup. Do you consult? I'm thinking about taking this application mainstream but there's quite a bit of work that still needs done. Email me at doug@coders4hire.com if there's any interest. Doug |
|||
| By: wtgee | Date: 03/08/2003 23:35:00 | Type : Answer |
|
| Session variables have a timeout specified in your php.ini file but they take care of themselves for the most part. You can switch around the properties in php.ini throught ini_set() (<A HREF="http://us2.php.net/manual/en/function.ini-set.php">http://us2.php.net/manual/en/function.ini-set.php</a>) but for the most part you probably won't need to. I'll send you an email about the app. :) |
|||
| By: VGR | Date: 04/08/2003 00:23:00 | Type : Comment |
|
| yes, session variables are : -deallocated at each request (HTTP is stateless) -re-read also at each request (same reason) -thus no need to deallocate them Their value will disappear if the session is closed, which means : -explicit session_delete -the browser instance is closed -the timeout (mentioned above, 20 minutes usually) expires and the same browser instance stays on (or gets back to) the site |
|||
| By: sumotimor | Date: 04/08/2003 00:58:00 | Type : Assist |
|
| Also, session variables are (by default) saved to a file. Periodically these session files are deleted when no longer needed. Calling session_terminate() will delete the session file for you, but it's not essential. I do think it's good coding practice to release any resources after you're done with them, but PHP will handle just about everything for you. If you have an unusually long session lifespan and a site with many visitors, the session files can get out of hand if you save a lot of info in the sessions. The longer the duration of your pages, the more important it is to manage your resources. Almost all PHP pages are pretty quick, and do one thing and then terminate, at which point PHP can release any resources. |
|||
|
Do register to be able to answer |
|||
| Add This Article To: | |||
| |
|
|
|
| |
|
|
|








