Page 1 of 1

php web site performance

Posted: Sun Aug 15, 2004 8:35 pm
by phpbaby
Hi,

I am using php/mysql for a website. My pages seem to load pretty slowly and I would like some advice on how to go about finding where the bottleneck is, whether it is the server, php script, or mysql queries, or something else.

Thanks!

Posted: Sun Aug 15, 2004 8:43 pm
by hawleyjr
What are you trying to do? Its hard to help without knowing what your doing. What does your code look like?

Posted: Sun Aug 15, 2004 8:56 pm
by phpbaby
sorry for such a general question.

The main goal is to speed up the loading times as users are complaining of long loading times.

I have a big file named mysql.php that contains classes for all the objects that I am using. It provides methods for retrieving various objects from the database. Since we are a game website, our main object is a game. So the code is something like that following:

Code: Select all

class Game{
  function Game ($id, $name, $platformID, $publisherID, $developerID, $date,  $ratingID, $introduction){
    // sets the fields
  }

  // methods for retrieveing games from the database

		function getGame ($gameID){
			$DB = getDB();
			$result = $DB->query ("select * from Game where gameID = $gameID") or die ("Could not retrieve game");
			$games = Game::getGamesFromResult ($result);
			return $gamesї0];
		}

}
The method Game:getGamesFromResult will go through the result and create games object, returning as an array.

The file mysql.php is 1700+ lines long, with all the various classes, and it is included by all other php pages requiring information from the database.

Is this approach ok, or is there room for optimization?


Posted: Sun Aug 15, 2004 11:07 pm
by Buddha443556
phpbaby wrote:The file mysql.php is 1700+ lines long, with all the various classes, and it is included by all other php pages requiring information from the database.
That sounds like a problem to me especially if a majority of it is unused on a page. That what about 70-80 KBs extra per page?

Posted: Mon Aug 16, 2004 3:13 am
by Grim...
Yeah, but only server-side. That shouldn't make too much difference.

Posted: Mon Aug 16, 2004 8:44 am
by pickle
Two things I can think of:

Time how long it takes to generate the page - use get a microtime timestamp when the PHP page is loaded, and compare it with a microtime timestamp generated at the end of the page.

Also, turn off implicit flushing - that will deliver the page to the browser as it is generated. If the page loads in a pretty even matter, it may be the clients connection, or it may just be that your page is inefficient. If the page takes a while to even start loading, but then loads quickly once it gets going, it is almost certainly your code.