On Tuesday 13 Nov 2001 17:05, René Fournier wrote:

> And concerning database connections, my ISP asks that I always close a
> MySQL connection with a mysql_close()--which I can understand.

They probably use persistent database connections for Apache. If that is the 
case, if you keep opening connections without closing them, eventually the 
system will run out of available connections. Similar things happen with 
mod_perl. You ALWAYS close your database connections.

> But I'm
> curious, if I have to make, say, 10 SELECTs throughout a page (in the
> header, body, and footer), is it perhaps faster to use the mysql_close()
> at the very end of the page (in the bottom of the footer.inc)? In other
> words, is there any disadvantage performance-wise (or stability reason)
> to open and immediately thereafter close mysql connections?

Yes, there is a performance hit. Open the database connection at the 
beginning of your page, and then close it at the end. It takes time to set up 
a database connection, albeit this is somewhat alleviated by using persistent 
connections. But you STILL have to do some work to access a connection from 
the connection pool.

> Can anyone recommend an article or two on coding techniques for
> improving PHP and MySQL performance? I don't wan to spend the rest of my
> life optimizing my php code, but if I knew a few basic rules about its
> performance characteristics, I might be able to make better decisions
> when coding. Thanks.

Using persistent connections, is a good start. Opening and closing database 
connections as rarely as possible is going to help, too, as long as you make 
sure all your open connections get closed when the script terminates.

Everything else is likely to be optimizations of PHP code or SQL code, 
separately.

Regards.

Gordan

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to