473,414 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Website too slow

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
8 2217


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
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
<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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

83
by: D. Dante Lorenso | last post by:
Trying to use the 'search' in the docs section of PostgreSQL.org is extremely SLOW. Considering this is a website for a database and databases are supposed to be good for indexing content, I'd...
3
by: aspnet guy | last post by:
my asp.net website is slow at my work machine but very fast at home. My work uses a firewall. Can that slow down the loading of web forms? are there any "common" things I can try to get it to...
0
by: clintonG | last post by:
I applied aspnet_regsql to SQL2K which was working fine throughout Beta 2 development. After installing Visual Studio and SQL Express RTM my application has blown up. Logging in to the application...
1
by: TCB | last post by:
I am developing a website using .NET 2.0 (classified style website) it displays a series of records per page (8, using a datagrid with paging) each record displays a thumbnail of an image that...
4
by: sommes | last post by:
It's only happen on .asp website, what's the problem? Thank you
2
by: Michele | last post by:
I have a website on IIS 6. With anonymous login the pages open immediatly. If i disable anonymous login and use integrated security the pages open very slow. Any idea? Thanks Michele
2
by: yasmike | last post by:
I am having a problem with my secure website on our internal network. The secure website is hosted on our Windows 2000 Server running IIS 5.0. If you try and access the website from a browser from...
3
by: cmk128 | last post by:
Hi I have a website , made by linux + mysql + php + apache. The user can search for 100000+ articles. The server is in hong kong, when the people browse the web from bejing , it is really slow. If...
10
by: penworthamnaynesh | last post by:
Does php slow your website down? This is what i would like to know.The reason is because my site is writtent 50% in html and 50% in php and is very slow at loading. And i cant tell wether php is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.