Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/105572-mysql-connection-close-issue/
Share on other sites

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.

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.

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. :)

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

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.  :o Should I just die or what. However, I will pretend, I haven't read your profile. ;) Just kidding....

*** BTW, I am 30 and I am taking advise from a 15 year old.  :o 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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.