0

I was taught to put mysqli_close in the footer.php that I include in every page as "best practice". ;)

From what I read here and here it is not exactly necessary, but would you go as far as saying it's bad practice?

Should I put the effort into removing it and only using it when necessary?

I can't imagine my server taking anything but a negligible performance hit from this extra line of script. Am I wrong?

Community
  • 1
  • 1
ZZ9
  • 2,177
  • 2
  • 27
  • 38

2 Answers2

1

If you don't release a resource that is in use in your script, it will be released when your script has completed. So, you aren't saving much more than a few bytes of disk space by removing it. The process of releasing the resource will happen with or without the mysqli_close.

kainaw
  • 4,256
  • 1
  • 18
  • 38
1

It's not best practice, it's not a very bad practice, it's not good practice.

As explained in the two Q/A you mentioned, mysqli_close has to be used when its needed : When you've done what you needed to do with your database AND when you still have many things to do in your script.

Short answer : Always using it at the very end of your scripts is 99.99% useless.

Clément Malet
  • 5,062
  • 3
  • 29
  • 48