By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

Website too slow

P: n/a
I'm re-programming my Website (www.coaster.ch) in PHP and I find it too
slow (although I have ADSL).
That's more or less how it functions:
Here my tables:
'COASTERS' (code of coaster, code of country, etc...)
'COUNTRIES' (code of country, names of countries in different
languages, code of continent)
'CONTINENTS' (code of continent, names of continents in different
languages)

In my index.php (start site) I use a "while":
I look for the first continent.
I look for the first country
I count all the coasters from 1st country
echo country - number of coasters
I look for the second country
I count all the coasters from 2nd country
....
....
I look for last continent....

The search and presentation in tables (I use 5 tables, 1 for each
continent) is rapid.
The problem is when I go the the sub-site of a country and want to come
back to the index site: it takes too much time.
Could it be that it is slow because it has to make the whole search
again?
Can I solve that by making the first search (at the begin of the
session with something like requireOnce "search data) and charge all
the information in an array and them when returning from a sub site
only showing the array?
I also thought that perhaps the reason could be that I use tables for
continents and countries but otherwise I should have to include all
these texts in .inc files...
Any idea will be welcomed.
Thank you.
Bettina

Jul 18 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a


be*****@coaster.ch wrote:
I'm re-programming my Website (www.coaster.ch) in PHP and I find it too
slow (although I have ADSL).
Speed of execution of PHP has nothing to do with the speed of your
connection. It has to do with the efficiency of your code and the speed
of the host.
That's more or less how it functions:
Here my tables:
'COASTERS' (code of coaster, code of country, etc...)
'COUNTRIES' (code of country, names of countries in different
languages, code of continent)
'CONTINENTS' (code of continent, names of continents in different
languages)

In my index.php (start site) I use a "while":
I look for the first continent.
I look for the first country
I count all the coasters from 1st country
echo country - number of coasters
I look for the second country
I count all the coasters from 2nd country
...
...


May we see you code. Without it, we will not be able to tell you how to
speed it up. It may be as simple as using a built in function instead
of a loop, or it could be a redesign of your logic.

Ken

Jul 18 '05 #2

P: n/a
Try to minimize the number of queries per page. Data that is
static--names of countries, continents--information, doesn't have to
be in the database. Keep them in an array in your code instead.

Jul 18 '05 #3

P: n/a
<body>
<?
include("connection.php");
include("banner.inc");
?>
<table class="main_table">
<tr>
<td height="30" width="20"></td>
<?
include("set_language.php");
?>
<td></td>
<td align="right">
<a href="brewery_list.php?lang=<? echo $lang ?>"><? echo
$link_to_breweries ?></a>&nbsp;&nbsp;
<a href="mailto:be*****@coaster.ch?subject=Bettinas
Bierdeckel-Sammlung"><? echo $contact ?></a>&nbsp;&nbsp;
<a href="sub_index.php?lang=<? echo $lang ?>"><? echo $info ?></a>
</td>
<td width="20"></td>
</tr>
</table>
<?
$count_coasters = mysql_query("SELECT COUNT(*) FROM coasters");
$total_coasters = mysql_result($count_coasters,0,0);
$count_countries = mysql_query("SELECT COUNT(*) FROM countries");
$total_countries = mysql_result($count_countries,0,0);
$GET_DATE = mysql_query("SELECT DATE_FORMAT(DATE,'%d.%m.%Y') FROM
coasters ORDER BY DATE DESC LIMIT 1");
$update = mysql_result($GET_DATE,0,0);
?>
<table class="main_table">
<tr class="blue_bar">
<td colspan="5" height="1"></td>
</tr>
<tr>
<td height="30" width="20"></td>
<td align="left" class="heading" width="328"><? echo
$total_coasters_text ?>&nbsp;<? echo $total_coasters ?></td>
<td align="center" class="heading" width="328"><? echo
$total_countries_text ?>&nbsp;<? echo $total_countries ?></td>
<td align="right" class="heading" width="328"><? echo $update_text
?>&nbsp;<? echo $update ?></td>
<td width="20"></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" class="main_table">
<tr>
<td>
<?
$search_continents = mysql_query("SELECT CONTINENT_CODE,
CONTINENT_$lang FROM continents ORDER BY CONTINENT_CODE ASC");
$i = 0;
while ($row = mysql_fetch_array($search_continents, MYSQL_NUM)) {
$continents[$i][0] = $row[0];
$continents[$i][1] = $row[1];
$key_continent = $continents[$i][0];
?>
<table align="left" class="sub_table_5">
<tr>
<td class="continent" colspan="4"><? echo $continents[$i][1]
?></td>
</tr>
<?
$search_countries = mysql_query("SELECT COUNTRY_CODE,
COUNTRY_$lang FROM countries WHERE CONTINENT_CODE = $key_continent
ORDER BY COUNTRY_$lang ASC");
$j = 0;
while ($row = mysql_fetch_array($search_countries, MYSQL_NUM)) {
$countries[$j][0] = $row[0];
$countries[$j][1] = $row[1];
$key_country = $countries[$j][0];
$count_coasters_country = mysql_query("SELECT COUNT(*) FROM
coasters WHERE COUNTRY_CODE = '$key_country'");
$total_coasters_country =
mysql_result($count_coasters_country,0,0);
$flag = $key_country.".gif";
?>
<tr>
<td><img src="Flags/<? echo $flag ?>"></td>
<td><a href="breweries.php?lang=<? echo $lang ?>&code_country=<?
echo $countries[$j][0] ?>"><? echo $countries[$j][1] ?></a></td>
<td align="right" class="no_link"><? echo
$total_coasters_country ?></td>
<td width="5"></td>
</tr>
<?
$j = $j + 1;
}
?>
</table>
<?
$i = $i + 1;
}
?>
</td>
</tr>
</table>

Jul 18 '05 #4

P: n/a
I will consider this point that you mention. Thank you.
I can do that with the continents, but the countries may vary in the
future, so I would have to change the programm and the idea is that i
only change the database.

Jul 18 '05 #5

P: n/a
be*****@coaster.ch wrote:
I will consider this point that you mention. Thank you.
I can do that with the continents, but the countries may vary in the
future, so I would have to change the programm and the idea is that i
only change the database.


In that case it's still possible to reduce the queries. For example:
Only query the countries table once per session. Once you retrieved the
list of countries keep them in a session-var, for use in the other
subpages. Just an idea.

--
http://www.phpforums.nl
Jul 18 '05 #6

P: n/a
In article <11**********************@o13g2000cwo.googlegroups .com>,
be*****@coaster.ch wrote:
<body>
<?
include("connection.php");
include("banner.inc");
?>
<table class="main_table">
<tr>
<td height="30" width="20"></td>
<?
include("set_language.php");
?>
<td></td>
<td align="right">
<a href="brewery_list.php?lang=<? echo $lang ?>"><? echo
$link_to_breweries ?></a>&nbsp;&nbsp;
<a href="mailto:be*****@coaster.ch?subject=Bettinas
Bierdeckel-Sammlung"><? echo $contact ?></a>&nbsp;&nbsp;
<a href="sub_index.php?lang=<? echo $lang ?>"><? echo $info ?></a>
</td>
<td width="20"></td>
</tr>
</table>
<?
$count_coasters = mysql_query("SELECT COUNT(*) FROM coasters");
$total_coasters = mysql_result($count_coasters,0,0);
$count_countries = mysql_query("SELECT COUNT(*) FROM countries");
$total_countries = mysql_result($count_countries,0,0);
I would use the PHP date functions for this - no sense asking the
database for it... unless your DB is on another machine and IT'S date is
more important than the machine PHP is running on.

If you must, you should be able to do:

SELECT DATE_FORMAT(DATE,'%d.%m.%Y')

without referencing a table and that other stuff.
$GET_DATE = mysql_query("SELECT DATE_FORMAT(DATE,'%d.%m.%Y') FROM
coasters ORDER BY DATE DESC LIMIT 1");
$update = mysql_result($GET_DATE,0,0);
?>
<table class="main_table">
<tr class="blue_bar">
<td colspan="5" height="1"></td>
</tr>
<tr>
<td height="30" width="20"></td>
<td align="left" class="heading" width="328"><? echo
$total_coasters_text ?>&nbsp;<? echo $total_coasters ?></td>
<td align="center" class="heading" width="328"><? echo
$total_countries_text ?>&nbsp;<? echo $total_countries ?></td>
<td align="right" class="heading" width="328"><? echo $update_text
?>&nbsp;<? echo $update ?></td>
<td width="20"></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" class="main_table">
<tr>
<td>
<?
Do you have an index on CONTINENT_CODE in your table definition?
$search_continents = mysql_query("SELECT CONTINENT_CODE,
CONTINENT_$lang FROM continents ORDER BY CONTINENT_CODE ASC");
$i = 0;
while ($row = mysql_fetch_array($search_continents, MYSQL_NUM)) {
$continents[$i][0] = $row[0];
$continents[$i][1] = $row[1];
$key_continent = $continents[$i][0];
?>
<table align="left" class="sub_table_5">
<tr>
<td class="continent" colspan="4"><? echo $continents[$i][1]
?></td>
</tr>
<?
Index on CONTINENT_CODE,COUNTRY_... existing in the DB? I am beginning
to wonder if there is a better way to handle the lang aspect to this.
$search_countries = mysql_query("SELECT COUNTRY_CODE,
COUNTRY_$lang FROM countries WHERE CONTINENT_CODE = $key_continent
ORDER BY COUNTRY_$lang ASC");
$j = 0;
while ($row = mysql_fetch_array($search_countries, MYSQL_NUM)) {
$countries[$j][0] = $row[0];
$countries[$j][1] = $row[1];
$key_country = $countries[$j][0];
$count_coasters_country = mysql_query("SELECT COUNT(*) FROM
coasters WHERE COUNTRY_CODE = '$key_country'");
$total_coasters_country =
mysql_result($count_coasters_country,0,0);
$flag = $key_country.".gif";
?>
<tr>
<td><img src="Flags/<? echo $flag ?>"></td>
<td><a href="breweries.php?lang=<? echo $lang ?>&code_country=<?
echo $countries[$j][0] ?>"><? echo $countries[$j][1] ?></a></td>
<td align="right" class="no_link"><? echo
$total_coasters_country ?></td>
<td width="5"></td>
</tr>
<?
$j = $j + 1;
}
?>
</table>
<?
$i = $i + 1;
}
?>
</td>
</tr>
</table>

Jul 21 '05 #7

P: n/a
I really need the date of the last update from the database, not
today's date.
Now I've deleted the table with continents and included them in a
land.XX.inc... because the continents will not grown. But the problem
are the countries that they my grow. Somebody told me to put them in a
SESSION var, that would be really a SESSION Array... For example, I've
thought about the following:

$search_countries = mysql_query("SELECT COUNTRY_CODE,
COUNTRY_$lang FROM countries ORDER BY COUNTRY_CODE ASC");
$i = 0;
while ($row = mysql_fetch_array($search_countries, MYSQL_NUM)) {
$countries[$i][0] = $row[0];
$countries[$i][1] = $row[1];

$_SESSION['countries'] = $countries;

but now I don't know how to reference the individual items of my
SESSION Array:
Like this my be?
$_SESSION['countries'] [ i ][0];

$_SESSION['countries'] [ i ][2]; etc, etc

Jul 21 '05 #8

P: n/a
be*****@coaster.ch wrote:
$search_countries = mysql_query("SELECT COUNTRY_CODE,
COUNTRY_$lang FROM countries ORDER BY COUNTRY_CODE ASC");
$i = 0;
while ($row = mysql_fetch_array($search_countries, MYSQL_NUM)) {
$countries[$i][0] = $row[0];
$countries[$i][1] = $row[1];


Why not just:

$countries = array();
while ($row = mysql_fetch_array($search_countries,
MYSQL_NUM)) {
array_push($countries, $row);
}

$_SESSION['countries'] = $countries;

You'll get an array of arrays (== database rows) that way.
If you want to know what exactly is in your $_SESSION['countries'] array
use print_r($_SESSION['countries']) for debugging purposes. You'll know
how to reference the array elements then.

--
http://www.phpforums.nl
Jul 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.