Classes and performance bottlenecks

From: Date: Tue, 14 Aug 2001 05:22:21 +0000
Subject: Classes and performance bottlenecks
Groups: php.general 
Request: Send a blank email to php-general+get-62568@lists.php.net to get a copy of this message
I have a strange problem with PHP 4.0.4pl1 and above. It looks like including a file that contains classes can become a major performance bottleneck My machine is an Intel Pentium ]I[ 667Mhz, 128Mb RAM running RedHat Linux 7.1; I installed PHP as a DSO module. I used ab (Apache Benchmark) for benchmarking. The following application runs a very simple query and outputs the result: <?php $db = pg_pconnect("dbname=jokes user=foo password=xxxxxxxxx"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>test</title> </head> <body> <?php $res = pg_exec($db, "SELECT * FROM j_jokes ORDER BY posted DESC LIMIT 10"); echo "<table>"; for ($i=0; $i<pg_numrows($res);$i++) { echo "<tr>"; $row = pg_fetch_row($res, $i); for ($c=0;$c<count($row);$c++) echo "<td>$row[$c]</td>"; echo "</tr>"; } echo "</table>"; ?> </body> </html> It can process up to 200 requests per second depending on the size of the dataset. Sometimes it can do even more than that. I didn't optimize Apache and PostgreSQL for performance. However, the following "application" <?php require_once("Smarty.class.php"); require_once("DB.php"); ?> can process about 25 requests per second. My applications use Smarty, Pear DB and my own classes from several include files. Thus, they can hardly handle 10 requests per second. I tried to benchmark them in many different ways and I figured out that *including* a class takes a lot of time. Using those classes doesn't seem to change anything dramatically. Is it an inherent problem of using classes with PHP or is there something I can do about it?

« previous php.general (#62568) next »