18.1.20 Use persistent connectionsThis is NOT the latest copy of this book; click here for the latest version.
If you connect to a database with each script, consider using a persistent connection rather than a normal connection. For MySQL users, that is the difference between using mysql_pconnect() rather than mysql_connect(). Persistent connections remain connected even after your script has ended, which means that the next time a script asks for a connection, it uses the one that is already open - this saves a lot time negotiating passwords and such that can otherwise be used to execute important code.
Switching to persistent connections does not require any other change than adding a "p" in the function name - the parameters are still the same. If your database server is not on the same machine as your web server, consider using CLIENT_COMPRESS as the fifth parameter to your mysql_connect() /mysql_pconnect() call - it allows MySQL to compress data to save space, can drastically lower network bandwidth and transfer speed, particularly when reading in lots of data.
|
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|