Forum Moderators: coopster
Any help would be greatly appreciated, thanks again.
If the page is taking ages to load, could you not lower the amount of stories? Is your database slowing down the processing of the page i.e. is it taking 3 seconds to get the info from the database then 1 second for the page to load?
Are you selecting everything in the database then using php to select random stories, as this will take a long time to get 1.8 million in to php, for php to then echo 200, use SQL to limit the stories to 200.
So a while loop through 16 records, then list 20 stories per record.
For the 20 records using query
$res1=mysql_query("select * from stories where id=" . $id . " order by id desc limit 0, 20)
so there is a limit on what its bringing back.
So I guess my question is, how can I speed this up? Let me know if you would like anymore info, thanks..
res1=MYSQLQUERY(select * from postion where user=$username)
while(res1!EOF) = 16 records from table of 10k records
res2=MYSQLQUERY(select * from link where id=$id order by id desc limit 0, 25)
while(res2!EOF) = 25 records - total table is 1.8million records
print results....
This is the basic concept with some php spitting out between...
Thanks for your help, we have indexed applied I believe as many places as we can, thanks.
Also do you need to SELECT * or could you narrow down the number of columns returned? This would not speed it up much, but will help a bit if you dont actually need all of the columns.
No I dont need every single column from those.....for both my queries should I only put select id, info from instead of select *?
Does that help in speed usually? Thought it was quicker to do *? Thanks!
Dont know what problems you get with output buffering that involves headers...that is half of the reason that people use output buffering. To get around trying to send headers half way though there script.
Try putting header/menus in separate containers (like div). This could possibly help.
Example 1. This seems to force whole page on IE as everything is in one container (table).
<body>
<table>
<tr><td>My header and menus here</td></tr>
<tr><td>My content here</td></tr>
</table>
</body>
Example 2. In this example header is in its own container (div). Browser can show header container first, than load content container.
<body>
<div>My header and menus here</div>
<div>My content here</div>
</body>
There are all sorts of issues with trying to get a correct content length header. As I had pages taking about 20 seconds to load, when there was about 2k (buffered) of information being sent. However I was sending a content length header of about 8k, so the browsers were just timing out waiting for the remaining 6k. Problem sorted when I put the code in the correct order, so the content length was actually the compressed length not the uncompressed length...I should have read through the user comments in the manual as it is all in there, my that was my mistake not a problem with ob buffering, php or the browsers.
If you want to test the time it takes to run scripts then have a look at the comments under the microtime [uk3.php.net] section in the manual. As there are a load of timer examples, then you can test with your set-up on your server to find out what is faster for you.
One problem I am having is a most popular page takes forever to load! I have tried it all not sure what else to do..
Just selects by date and hits and displays, 3 times, day, week, month time periods
here are 3$time=mktime(date("H")-24,date("i"),date("s"),date("m"),date("d"),date("y"));
$res1=mysql_query("select id,title, pub_date, detail from table where pub_date>" . $time . " and (id) in (select id from category where postedby='admin' and linktype='text') order by hits desc limit 0,5");
echo mysql_error();
while($row1=mysql_fetch_array($res1))
{
spit out stuff
}
$time=mktime(date("H"),date("i"),date("s"),date("m"),date("d")-7,date("y"));
$res1=mysql_query("select id,title, pub_date, detail from table where pub_date>" . $time . " and (id) in (select id from category where postedby='admin' and linktype='text') order by hits desc limit 0,5");
echo mysql_error();
while($row1=mysql_fetch_array($res1))
{
spit out stuff
}
$time=mktime(date("H"),date("i"),date("s"),date("m")-1,date("d"),date("y"));
$res1=mysql_query("select id,title, pub_date, detail from table where pub_date>" . $time . " and (id) in (select id from category where postedby='admin' and linktype='text') order by hits desc limit 0,5");
echo mysql_error();
while($row1=mysql_fetch_array($res1))
{
spit out stuff
}
These 3 process 1st in 1 second, 2nd in 6 seconds, and 3rd in a wopping 21 seconds.
I cant see anywhere else to do and index are placed on all..
Thanks in advance
$time=mktime(date("H"),date("i"),date("s"),date("m")-1,date("d"),date("y"));
$time = [url=http://uk3.php.net/manual/en/function.strtotime.php]strtotime[/url]('-1 month');
...not that this will help with the page loading, but its a lot easier to read :)
Although I dont know if this will help a huge amount but it may be worth calling the mysql_free_result [uk3.php.net] after each while loop. As you are not using the results again and they will be held in memory. So freeing the results you dont need may speed things up for you.