简体   繁体   English

小页面加载时CodeIgniter的运行速度极其慢

[英]CodeIgniter incredibly slow on small page load

So i am experiencing a problem I should probably only be having on big pages but instead im getting that on ANY page. 所以我遇到一个问题,我可能应该只在大页面上,而在任何页面上都无法获取。

I am trying to make a REST api using CodeIgniter and it works but any page I load is very very slow. 我正在尝试使用CodeIgniter制作REST api,它可以工作,但是我加载的任何页面都非常慢。 I am talking 20-30 seconds page loads for a page worth 504 Bytes. 我说的是20到30秒的页面加载时间,总值504字节。

I've added extra benchmarks and it displays it takes roughly 0.04 sec to download the data. 我添加了额外的基准,它显示下载数据大约需要0.04秒。

Rankings.php (Controller) Ranks.php(控制器)

class Rankings extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('rankingsmodel');
    }

    /**
     * Index Page for this controller.
     */
    public function index()
    {
        $this->benchmark->mark('code_start');

        $rankings =$this->rankingsmodel->getAllRankings();
        $mappedRankings = array_map(array($this, 'mapRank'), $rankings, array_keys($rankings));

        $this->benchmark->mark('code_end');
        echo $this->benchmark->elapsed_time('code_start', 'code_end');

        return $this->jsonIFy($mappedRankings);
    }

    public function mapRank($ranking, $k)
    {
        $ranking['rank'] = $k;
        return $ranking;
    }

    public function jsonIFy(array $data = array())
    {
        echo json_encode($data);
    }
}

And my rankingsmodel 我的排名模型

class RankingsModel extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getAllRankings()
    {
        $this->benchmark->mark('code_start2');

        $query =$this->db->query('SELECT * FROM characters3 WHERE gm < 3 ORDER BY rebirths DESC')->result_array();

        $this->benchmark->mark('code_end2');
        echo $this->benchmark->elapsed_time('code_start2', 'code_end2');
        return $query;
    }
}

I have absolutely no idea why page loads so incredibly slow while my benchmarks are saying it would take 0.03/0.04 to load. 我完全不知道为什么页面加载速度如此之慢,而我的基准测试却表明加载页面需要0.03 / 0.04。 I've tried setting up xdebug but i've not had any luck setting it up. 我试过设置xdebug,但是没有设置它的运气。 Im using regular mysqli drivers that come with codeigniter. 我正在使用codeigniter附带的常规mysqli驱动程序。

Does anyone have any idea why it is so slow or any tool i can setup easily to debug? 有谁知道为什么它这么慢或者我可以轻松设置任何工具进行调试?

Thank you 谢谢

Okay so after a few more hours of digging i have found the problem. 好了,经过几个小时的挖掘,我发现了问题所在。

The problem is the following: 问题如下:

My database was getting retrieved very slowly (we have a demo on db4free or smth) and that is what was taking so long. 我的数据库的检索速度非常慢(我们在db4free或smth上有一个演示),这花费了很长时间。 We also had $db['default']['pconnect'] set to false which meant we had to constantly reconnect to the database. 我们还把$db['default']['pconnect']设置为false,这意味着我们不得不不断地重新连接数据库。

For testing purposes setting pconnect to true will solve the issue. 出于测试目的,将pconnect设置为true将解决此问题。 And oh: get a faster database for production. 哦:获得更快的生产数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM