减少网站的等待时间

发布于 2024-12-02 13:11:09 字数 1879 浏览 0 评论 0原文

我们正在尝试创建一个新网站,当我在浏览器上写下我的网站的链接时 例如: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.'&amp;h=107&amp;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南…巷孤猫 2024-12-09 13:11:09

许多不同的因素都会影响页面加载时间。三个最大的问题是:

  1. 服务器滞后
  2. 内容过载
  3. 编程不良

在没有有关您网站的更多详细信息的情况下,我将简要描述如何诊断和修复这三个大问题。如果您在对此答案的评论中提供您的网站链接,我可以更具体。

服务器延迟

当您尝试连接到您的网站,并且连接挂起一段时间时,就会发生这种情况。此外,这可能会有一个空白页面,该页面会旋转一段时间,然后最终开始加载您的内容。

除了切换主机或与主机合作增加带宽和服务器连接之外,您无法自行解决此问题。

内容过载

最好的例子是当您看到有人在一页上放置大量图像时。请记住,您添加的每个图像都要求用户在加载页面之前下载该图像。这包括 标签以及 background-image 中的内容。

糟糕的编程

这种情况的症状类似于服务器延迟,您必须等待一段时间才能开始加载内容。这可能是由多种原因造成的,从缓慢的数据库连接到多个嵌套循环。如果不查看完整代码,很难诊断。

Well a number of different factors can affect your page load time. The three biggest being:

  1. Server Lag
  2. Content Overload
  3. Poor Programming

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 as background-imagees.

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.

疯了 2024-12-09 13:11:09

这很大程度上取决于您的网站的用途。我建议从分析开始。它将帮助您确定您的努力以获得最大收益。

您也是正确的选择Firebug Net 选项卡,查看Yslow 也是如此。

一般情况:

  • 检查服务器 CPU 使用情况、网络延迟 (ping) 等。解决任何问题。
  • 获取更多内存和/或更有效地使用它。下面的大部分内容都是由此而来。
  • 缓存昂贵的操作
  • 提高数据库速度
    • 减少每页执行的查询数量
    • 将数据库拆分到另一台服务器以减少争用
  • 用 使用反向代理/缓存将请求划分到多个前端 Web 服务器。
  • 将应用程序服务器拆分为自己的服务器。
  • 优化页面资源以实现快速交付
    • 将 CSS 和 JS 文件合并为一个文件。
    • 缩小它们 - 删除无关的字符
  • 对所提供的所有文本文件使用 Gzip 压缩。
  • 使用 CDN 将资产卸载到其他域,显着提高现代浏览器上的并行性能。
    • 图像应从其他域提供。
    • 如果可能的话,还有 CSS/JS。

这些内容在:

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:

  • Check server CPU usage, network latency (ping) etc. Resolve any issues.
  • Get more RAM and/or use it more effectively. Most of the items below follow from this.
  • Cache expensive operations
  • Increase speed of the database
    • Reduce the number of queries performed per page
    • Split database to another server(s) to reduce contention
  • Use a reverse proxy/cache to divide requests to several front-end web servers.
  • Split application server to its own server(s).
  • Optimize page assets for quick delivery
    • Combine CSS and JS files into one file each.
    • Minify them - remove extraneous characters
  • Use Gzip compression on all text files served.
  • Use CDN's to offload assets to other domains, improves parallel performance drastically on modern browsers.
    • Images should be served from another domain.
    • If possible CSS/JS also.

These are well detailed at:

苍风燃霜 2024-12-09 13:11:09

解决方案:
对于慢速脚本:使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文