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!
php web site performance
Moderator: General Moderators
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:
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?
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 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?
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
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.
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.