【问题标题】:Getting 503 Service Unavailable on Codeigniter in Apache Server在 Apache 服务器的 Codeigniter 上获取 503 服务不可用
【发布时间】:2021-03-12 09:51:45
【问题描述】:

我正在 Apache 服务器 (XAMPP) 上使用 Codeigniter 3,但我的实时服务器 (CentOS) 出现问题。当我尝试加载新视图时,没有出现问题。但是,当我尝试在旧视图完成加载之前多次(如 5 次)加载新视图时,服务器崩溃并给我一个 503 错误。

当用户尝试使用导航菜单并看到页面加载缓慢时,我们发现了这个错误,因为数据库很慢,他很快尝试加载新页面。

此错误出现在所有视图中,无论它们多么简单或复杂。

这是一个产生错误的视图示例。

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

class Example_controller extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('example_model');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->helper('url');
    }

    public function index()
    {
        $data['information'] = $this->example_model->get_data();

        $this->load->view('header');
        $this->load->view('body', $data);
        $this->load->view('footer');
    }
}

在这个例子中,数据库函数是一个非常简单的 Select 查询。我正在使用 Oracle SQL 数据库。

我还尝试更改 .htaccess 文件以允许更多时间使服务器超时,但这没有用。

这是我当前的 .htaccess 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

我一直在寻找答案很长时间,我将非常感谢您能给我的任何帮助。提前致谢。

【问题讨论】:

  • 这似乎与您的代码或 htaccess 无关,因为两者看起来都很好。如果没有更多信息,我的建议是检查您的 Apache 配置(它可以产生多少个进程,您的服务器在开始接收请求时有多少可用资源等)。 Apache 错误日志也可能提供一些有用的见解。话虽如此,这看起来可以在 ServerFault 中更好地解决

标签: php performance apache .htaccess codeigniter


【解决方案1】:

我认为您无法使用 CI 提供的 redirect() 函数设置 503 HTTP 状态。但是你可以设置301代码(临时重定向),这意味着搜索引擎会知道你的页面是临时重定向的,它不会索引维护页面。

More info here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 2017-01-14
    • 1970-01-01
    • 2017-08-23
    • 2021-04-12
    • 2015-08-17
    • 1970-01-01
    相关资源
    最近更新 更多