Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Use Persistent Connections

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 of 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, as it allows MySQL to compress data to save space, and can drastically lower network bandwidth and transfer speed, particularly when reading in lots of data.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page