2012-05-21 87 views
0

我想,因爲它永遠掛在我嘗試用幾個職位加載一個頁面上我笨的應用程序在我的服務器返回一個500錯誤調試問題。這個模型結構是否容易出現無限循環?

此錯誤是間歇性的。 10次​​中的7次,我的頁面加載速度快,CI的分析器顯示執行時間< 0.6。

該模型使用這樣的結構,其中來自不同的條款將取決於正在取得(即,我的職位,收藏,其它帖子)的請求被插入。沒有SQL錯誤,沒有PHP錯誤。只有在處理顯著延遲和一些Apache的錯誤,如

[Sat May 19 21:27:21 2012] [warn] mod_fcgid: process 21174 graceful kill fail, sending SIGKILL 
[Sat May 19 21:27:27 2012] [notice] mod_fcgid: process /var/www/vhosts/example.com/httpdocs/blog/index.php(21174) exit(communication error), get stop signal 9 

就是這種SQL模式容易產生無限循環或一些其他類型的可以證明我的服務器要發狂了問題?

class Home_model extends CI_Model { 

    function __construct() 
    { 
     parent::__construct(); 
    } 

    function count_posts($author_id = NULL, $section = NULL, $user_id = NULL, $origin = NULL) 
    { 
     $clause = $this->clause($author_id, $section, $user_id, $origin); 

     $query = $this->db->query(" 
     SELECT * 
     $clause 
     "); 

     return $query->num_rows; 
    } 

    function clause($author_id, $section, $user_id, $origin = NULL) 
    { 
     if ($section == 'favorites') { 

      $clause = "FROM post RIGHT JOIN favorites ON post_id_fk = post_id WHERE user_id_fk = $user_id"; 

     } elseif (($section == 'posts') AND ($origin == 'user')) { 

      $clause = "FROM post WHERE post_author_id = $author_id"; 

     } else { 

      if ($author_id == NULL) { 

       $clause = "FROM post"; 

      } else { 

       $clause = "FROM post WHERE post_author_id = $author_id"; 
      } 
     } 

     return $clause; 
    } 
} 
+2

它肯定容易受到SQL注入傳遞 – Galen

+0

無屬性都是經得起用戶輸入 - 循環如何? – pepe

回答

0

我猜,在你看來,你這樣做

for ($i=0; $i<$this->count_posts(); $i++){ 
     // show posts 
    } 

能否請您發表您的看法碼?

但考慮到你可能做類似的東西 - 這將是合理的假設,模型中的count_posts()函數返回的可能錯誤的號碼,造成你的循環變得無限大。

調試它,像做

//for ($i=0; $i<$this->count_posts(); $i++){ 
     // show posts 
// } 
echo $count_posts(); 

,看看輸出始終是你所期望的......