减少网站的等待时间
我们正在尝试创建一个新网站,当我在浏览器上写下我的网站的链接时 例如:www.mywebsite.com,等待时间有点长。
我看到一些网站的等待时间比我的网站要短,有什么方法可以减少等待时间,我们也在网站上使用 memcached 吗?
PS:我不知道到底是如何调用的,但我用萤火虫看到它,它说等待时间。
谢谢。
编辑
这是我用来从数据库获取数据的代码:
function f3($id = '') {
$id = mysql_real_escape_string ($id);
$sql = 'SELECT id,post_title,post_content,post_date,post_status,term_taxonomy_id,object_id FROM wp_posts, wp_term_relationships WHERE term_taxonomy_id = 60 AND post_status = "publish" AND wp_term_relationships.object_id = id ORDER BY post_date DESC LIMIT 1 OFFSET 2';
$res = mysql_query($sql) or die (mysql_error());
if (mysql_num_rows($res) !=0):
$row = mysql_fetch_assoc($res);
$mycontent = $row['post_content'];
$mycontent = strip_tags($mycontent);
$mycontent = substr($mycontent,0,150);
$mycontent = preg_replace("/\[caption.*\[\/caption\]/", '', $mycontent);
$title = AvinD($row['post_title']);
$old_date = $row['post_date']; // returns Saturday, January 30 10 02:06:34
$old_date_timestamp = strtotime($old_date);
$new_date = date('d.m.Y H:i', $old_date_timestamp);
$first_img = '';
$my1content = AvinD($row['post_content']);
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $my1content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/img/default.png";
}
echo '
'.$new_date.'
<a href="single.php?id='.$row['id'].'"> '.$title.' </a> </div>
<a href="single.php?id='.$row['id'].'"> <img src="timthumb.php?src='.$first_img.'&h=107&w=190amp;zc=1" alt="" /> </a> </div>
'.$mycontent.'
'; //echo
else:
echo 'Page dont exist';
endif;
} // end
We are trying to create a new website, and when i write the link of my website on the browser
ex: www.mywebsite.com, the waiting time is a bit high.
I have seen some website that has a lower waiting time then mine, is any way to decrease the waiting time , also we are using memcached for the website?
PS: idk exactly how is called, but i see it with firebug, and it says waiting time.
Thank you.
EDITED
This is the codes i have used to get data from database:
function f3($id = '') {
$id = mysql_real_escape_string ($id);
$sql = 'SELECT id,post_title,post_content,post_date,post_status,term_taxonomy_id,object_id FROM wp_posts, wp_term_relationships WHERE term_taxonomy_id = 60 AND post_status = "publish" AND wp_term_relationships.object_id = id ORDER BY post_date DESC LIMIT 1 OFFSET 2';
$res = mysql_query($sql) or die (mysql_error());
if (mysql_num_rows($res) !=0):
$row = mysql_fetch_assoc($res);
$mycontent = $row['post_content'];
$mycontent = strip_tags($mycontent);
$mycontent = substr($mycontent,0,150);
$mycontent = preg_replace("/\[caption.*\[\/caption\]/", '', $mycontent);
$title = AvinD($row['post_title']);
$old_date = $row['post_date']; // returns Saturday, January 30 10 02:06:34
$old_date_timestamp = strtotime($old_date);
$new_date = date('d.m.Y H:i', $old_date_timestamp);
$first_img = '';
$my1content = AvinD($row['post_content']);
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $my1content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/img/default.png";
}
echo '
'.$new_date.'
<a href="single.php?id='.$row['id'].'"> '.$title.' </a> </div>
<a href="single.php?id='.$row['id'].'"> <img src="timthumb.php?src='.$first_img.'&h=107&w=190amp;zc=1" alt="" /> </a> </div>
'.$mycontent.'
'; //echo
else:
echo 'Page dont exist';
endif;
} // end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
许多不同的因素都会影响页面加载时间。三个最大的问题是:
在没有有关您网站的更多详细信息的情况下,我将简要描述如何诊断和修复这三个大问题。如果您在对此答案的评论中提供您的网站链接,我可以更具体。
服务器延迟
当您尝试连接到您的网站,并且连接挂起一段时间时,就会发生这种情况。此外,这可能会有一个空白页面,该页面会旋转一段时间,然后最终开始加载您的内容。
除了切换主机或与主机合作增加带宽和服务器连接之外,您无法自行解决此问题。
内容过载
最好的例子是当您看到有人在一页上放置大量图像时。请记住,您添加的每个图像都要求用户在加载页面之前下载该图像。这包括
标签以及
background-image
中的内容。糟糕的编程
这种情况的症状类似于服务器延迟,您必须等待一段时间才能开始加载内容。这可能是由多种原因造成的,从缓慢的数据库连接到多个嵌套循环。如果不查看完整代码,很难诊断。
Well a number of different factors can affect your page load time. The three biggest being:
Without having more details about your website, I'll briefly describe how to diagnose and fix these three big problems. If you provide your website link in a comment on this answer I can be more specific.
Server Lag
This happens when you try to connect to your website, and it hangs for a while connecting. Moreover this can have a blank white page which spins for a while, then finally begins to load your content.
You cannot fix this on your own other than switching hosts, or working with your host to increase your bandwidth and server connection.
Content Overload
The best example of this is when you see someone put tons of images on one page. Keep in mind that every image you add requires the user to download this image before the page is loaded. This includes those in
<img>
tags as well asbackground-image
es.Poor Programming
A symptom of this would be similar to server lag, where you have to wait a while before content begins to load. This can result from a number of things, from a slow Database connection to multiple nested loops. Very difficult to diagnose without looking at the full code.
这很大程度上取决于您的网站的用途。我建议从分析开始。它将帮助您确定您的努力以获得最大收益。
您也是正确的选择Firebug Net 选项卡,查看Yslow 也是如此。
一般情况:
这些内容在:
A lot of it depends on what your site does. I recommend starting by profiling. It will help you pinpoint your effort for maximum gain.
You are also the right track with the Firebug Net tab, check out Yslow as well.
In general:
These are well detailed at:
解决方案:
对于慢速脚本:使用 firebug & Firefox 的 YSlow 插件可以检测是什么拖慢了你的速度。
对于速度较慢的服务器:使用 cloudflare 来加速您的服务器,最高可达 60% 或更改您的托管公司。
solutions:
For Slow script: use firebug & YSlow Plugin for firefox to detect what slows you down.
For Slow Server: use cloudflare to speed up your server, up too 60% or change your hosting compney.