Codeigniter 网站加载某些页面大约需要 30 秒

发布于 2024-11-17 11:05:07 字数 1225 浏览 2 评论 0原文

我有一个 codeigniter 网站,可以在 localhost 上完美运行,但现在我已将其移至 Host gator,如果加载的话,一些页面请求大约需要 30 秒才能提供!奇怪的是,这似乎是随机的,在等待页面加载时,如果我只需重新单击链接,页面就会正常加载。我不确定这是否是我的控制器中的编程问题(下面的代码)或只是主机鳄鱼端的问题。请有人帮助我,因为我快疯了。

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Company extends CI_Controller
{
function __construct()
{
    parent::__construct();

    if (!$this->session->userdata('language')) $this->session-    >set_userdata('language', 'en');
}

function index ()
{
    $tags['title'] = 'title tag';

    $this->load->view($this->session->userdata('language').'/includes/view_header',$tags);
    $this->load->view($this->session->userdata('language').'/company/view_company');
    $this->load->view($this->session->userdata('language').'/includes/view_footer');    
}

function warranty ()
{
    $tags['title'] = 'title tag';

    $this->load->view($this->session->userdata('language').'/includes/view_header',$tags);
    $this->load->view($this->session->userdata('language').'/company/view_warranty');
    $this->load->view($this->session->userdata('language').'/includes/view_footer');        
}
}

I have a codeigniter website that runs beautifully on localhost, but now that I have moved it to Host gator some page requests are taking around 30 seconds to serve up, if loaded at all! The weird thing is that is seemingly random, and while waiting for the page to load, if I simply re-click the link the page will load normally. I'm not sure if this is a programming problem in my controllers (code below) or just issues on host gators end. Please plesse please someone help me out here, as I am going insane.

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Company extends CI_Controller
{
function __construct()
{
    parent::__construct();

    if (!$this->session->userdata('language')) $this->session-    >set_userdata('language', 'en');
}

function index ()
{
    $tags['title'] = 'title tag';

    $this->load->view($this->session->userdata('language').'/includes/view_header',$tags);
    $this->load->view($this->session->userdata('language').'/company/view_company');
    $this->load->view($this->session->userdata('language').'/includes/view_footer');    
}

function warranty ()
{
    $tags['title'] = 'title tag';

    $this->load->view($this->session->userdata('language').'/includes/view_header',$tags);
    $this->load->view($this->session->userdata('language').'/company/view_warranty');
    $this->load->view($this->session->userdata('language').'/includes/view_footer');        
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

可是我不能没有你 2024-11-24 11:05:07

我建议您使用 codeigniter profiler 进行测试,它将显示所有处理时间,例如 sql 执行等...

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Company extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->output->enable_profiler(TRUE);
        if (!$this->session->userdata('language')) $this->session-    >set_userdata('language', 'en');
    }

启用后,将生成一个报告并将其插入到页面底部。

要禁用您将使用的探查器:

$this->output->enable_profiler(FALSE);

有关更多详细信息 http://codeigniter.com/user_guide/libraries/ output.html

希望这会对您有所帮助,如果有任何问题请告诉我们...谢谢!

I suggest you to test with codeigniter profiler, It will show all the processing time like sql execution etc...

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Company extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->output->enable_profiler(TRUE);
        if (!$this->session->userdata('language')) $this->session-    >set_userdata('language', 'en');
    }

When enabled a report will be generated and inserted at the bottom of your pages.

To disable the profiler you will use:

$this->output->enable_profiler(FALSE);

For more details http://codeigniter.com/user_guide/libraries/output.html

Hope this will help you, let us know if anything there... Thanks!!

天邊彩虹 2024-11-24 11:05:07

您的网站上有 Javascript 或外部文件吗?这可能就是问题所在。

尝试使用 Firebug/YSlow,您可能会发现外部 js/文件(例如 Facebook 或 Twitter js)是否需要花费大量时间来加载。

Do you have any Javascript or external file on your site? That might be the problem.

Try using Firebug/YSlow and you'll probably get if an external js/file (Facebook or Twitter js for example) is taking lot of time to load.

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