13.3. Persistent Connections and Performance
After giving you a slight insight into PHP's internals and after you have seen what processes are running, it's time to have a look at what effects on speed persistent database connections have.
The next example shows a script that connects and disconnects to the database 25,000 times. In addition, the average time needed to connect to a database once is computed:
<?php $number = 25000; # Number of connections $begin = time(); # Starting time for ($i = 0; $i < $number; $i++) { $dbh = pg_pconnect("host=localhost user=postgres dbname=phpbook"); if (!$dbh) { echo "error while connecting.<br>\n"; } pg_close($dbh); } $end = time(); # Ending time $diff = $end - $begin; # Overall time $tpconn = $diff / $number; ...
Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.