tkm Posted May 14, 2008 Share Posted May 14, 2008 Hello Mates, I think I am not being able to close mysql connection properly from php. Here is what I am doing: mysql_connect($connection); function x() { global $connection; mysql_select_db($db_name,$connection); ...code...code...code... mysql_close($connection); } function y() { global $connection; mysql_select_db($db_name,$connection); ...code...code...code... mysql_close($connection); } Is my approach above ok? Or am I doing crap? Any suggestion would be great help. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/ Share on other sites More sharing options...
MadTechie Posted May 14, 2008 Share Posted May 14, 2008 What you have looks okay, what makes you think its not closing ? as a note:~ Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540784 Share on other sites More sharing options...
tkm Posted May 14, 2008 Author Share Posted May 14, 2008 What you have looks okay, what makes you think its not closing ? as a note:~ Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. Thank you, for the reply. Well it seems that it is taking longer and longer every time I invoke the script. I am assuming it is slowing down mysql memory/resource/connection-capability and for which it is gradually slowing down. My page works fast in the morning but gradually slows down during the day. It could very well may be other issues but I just want to make sure my php connection procedure is perfect. Thank you, again on your reply. Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540791 Share on other sites More sharing options...
MadTechie Posted May 14, 2008 Share Posted May 14, 2008 could it be the server traiffic ? are you on a shared server, is it always at the same time (could be backups) check your not using mysql_pconnect, when unneeded. check the logs for images leachers etc Thanks to the reference-counting system introduced with PHP 4's Zend Engine, a resource with no more references to it is detected automatically, and it is freed by the garbage collector. For this reason, it is rarely necessary to free the memory manually. Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540798 Share on other sites More sharing options...
tkm Posted May 14, 2008 Author Share Posted May 14, 2008 could it be the server traiffic ? are you on a shared server, is it always at the same time (could be backups) check your not using mysql_pconnect, when unneeded. check the logs for images leachers etc Thanks to the reference-counting system introduced with PHP 4's Zend Engine, a resource with no more references to it is detected automatically, and it is freed by the garbage collector. For this reason, it is rarely necessary to free the memory manually. Thank you. I will do. Your suggestions are very constructive. Take care. Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540807 Share on other sites More sharing options...
DarkWater Posted May 14, 2008 Share Posted May 14, 2008 Why do you select the database separately in both functions? Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540811 Share on other sites More sharing options...
tkm Posted May 14, 2008 Author Share Posted May 14, 2008 Why do you select the database separately in both functions? Hmmm....good question. ??? I understand if I just put the select database function at the top of the page, that should do. Isn't that what you were refering to? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540813 Share on other sites More sharing options...
DarkWater Posted May 14, 2008 Share Posted May 14, 2008 Yes, put it outside of the functions, right after your connection. Also, try benchmarking your script to see which parts are taking long to load. Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540814 Share on other sites More sharing options...
MadTechie Posted May 14, 2008 Share Posted May 14, 2008 from my understanding, its not the loading thats the problem, its seams that the system is getting cloged at times, this could be, depending on the system design, it may be an idea to add some caching.. but you really need to find where the problem is, if you had a query doing a massive search on a common page then that would cause problems.. without more info its very hard to say, what the problem could be, i would refer to the logs Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540822 Share on other sites More sharing options...
tkm Posted May 14, 2008 Author Share Posted May 14, 2008 Yes, put it outside of the functions, right after your connection. Also, try benchmarking your script to see which parts are taking long to load. Thank you. I will do that. *** BTW, I am 30 and I am taking advise from a 15 year old. Should I just die or what. However, I will pretend, I haven't read your profile. Just kidding.... Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540826 Share on other sites More sharing options...
MadTechie Posted May 14, 2008 Share Posted May 14, 2008 *** BTW, I am 30 and I am taking advise from a 15 year old. Should I just die or what. However, I will pretend, I haven't read your profile. Just kidding.... Off subject: Humm so if he was 30 and a doctor and you was 90 would you go under his knife ? then again if he was 90 would you go under his knife ? Scary thought! Quote Link to comment https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/#findComment-540830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.