用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2975|回复: 7
收起左侧

[HELP] 为什么框架变得这么慢啊

[复制链接]
发表于 2012-2-21 11:57:54 | 显示全部楼层 |阅读模式
本帖最后由 wunayou 于 2012-2-21 12:00 编辑

这是模型
<?phpclass MHome extends CI_Model{        function __construct()         
{                 parent::__construct();      
   }
         function get_category()      
  {                                  $query=$this->db->query('select * ,(select count(brand) from product where brand=product_brand.name) as product_count from product_brand;');                                          
return $query->result();         }
}   
?>

<?php
class Mbrand extends CI_Model{        
function __construct()      
  {               
parent::__construct();                        
}
var $id;        
function get_product($id,$page)         
{                 $query=$this->db->query("select * from product where brand=(select name from product_brand where id=$id)limit 0,$page");                                 
return $query->result();                          }
function get_product_num($id)      
{                 $query=$this->db->query("select * from product where brand=(select name from product_brand where id=$id)");                                   
return $query->num_rows();                     
     }
}
?>





这是控制器
<?php
class Brand extends CI_Controller
{
        function __construct()
         {
                 parent::__construct();
                 $this->load->helper('url');
                 $this->load->database();
                 $this->load->model('Mhome');
                 $this->load->model('Mbrand');
                 $this->load->library('pagination');
         }
         function watches()
         {
                 

$config['base_url']=base_url().'brand/watches/'.$this->uri->segment(3);
$config['total_rows'] = $this->Mbrand->get_product_num($this->uri->segment(3));
$config['uri_segment'] = 4;
        $config['per_page'] = 5; // 每页显示数量,为了能有更好的显示效果,我将该数值设置得较小
        $config['num_links'] = 3; // 当前连接前后显示页码个数
        $this->pagination->initialize($config);
      $data['category']=$this->Mhome->get_category();
                 $data['brand']=$this->Mbrand->get_product($this->uri->segment(3),$config['per_page']);
          $this->load->view('header',$data);
                 $this->load->view('brand');
                 $this->load->view('footer');
                 
         }
}
?>

代码都在这里 为什么打开网页就好像是12M网速变成1M还恐怖



发表于 2012-2-21 15:06:22 | 显示全部楼层
看下哪里慢,这个需要监控下。
 楼主| 发表于 2012-2-21 15:08:33 | 显示全部楼层
Hex 发表于 2012-2-21 15:06
看下哪里慢,这个需要监控下。

怎么样监控? 用什么软件?
发表于 2012-2-21 15:10:43 | 显示全部楼层
 楼主| 发表于 2012-2-21 16:04:07 | 显示全部楼层
Hex 发表于 2012-2-21 15:10
http://codeigniter.org.cn/user_guide/libraries/benchmark.html

我看了一下 是我控制器慢了  用了1.7056     总网站用了1。96mb 是我数据库的原因吗? 还是我电脑的原因?
发表于 2012-2-21 17:27:30 | 显示全部楼层
一般来说慢都是数据库慢。
 楼主| 发表于 2012-2-21 17:38:08 | 显示全部楼层
Hex 发表于 2012-2-21 17:27
一般来说慢都是数据库慢。

请问 我的那个分页 那个LAST 不是下一页也在网址后面多加了一零
发表于 2012-2-21 18:34:30 | 显示全部楼层
wunayou 发表于 2012-2-21 17:38
请问 我的那个分页 那个LAST 不是下一页也在网址后面多加了一零

分页显示的是偏移量,不是页数。
这是老外的习惯。。。。

本版积分规则