php web site performance

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
phpbaby
Forum Newbie
Posts: 2
Joined: Sun Aug 15, 2004 8:35 pm

php web site performance

Post 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!
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

What are you trying to do? Its hard to help without knowing what your doing. What does your code look like?
phpbaby
Forum Newbie
Posts: 2
Joined: Sun Aug 15, 2004 8:35 pm

Post 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?

User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Yeah, but only server-side. That shouldn't make too much difference.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply