2012-02-15 73 views
0

我一直在研究一個小MVC項目,以協助我的自我學習,並且遇到了讓我完全困惑的問題。我在這個MVC-ish系統中創建了一個博客部分,並從ACL中提取了用戶權限,沒有任何問題。 我移動到創建一個部件區段,一旦我添加任何的權限檢查我從Chrome中出現以下錯誤:收到 無法因爲服務器發送任何數據,加載網頁兩個(幾乎)相同的代碼段產生單獨的結果

無數據。 以下是一些建議: 稍後重新加載此網頁。 錯誤324(net :: ERR_EMPTY_RESPONSE):服務器關閉連接而不發送任何數據。

我認爲這很奇怪,所以我再次檢查我的錯誤日誌,沒有顯示出來。所以我決定將工作博客代碼複製並粘貼到成員文件中,重新加載並得到相同的錯誤,現在兩個文件之間的唯一區別是文件名和類名。 以下是博客的代碼:

<?php 
class blog extends frontController { 
    public $model; 
    public $user; 

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

     $this->model = $this->autoload_model(); 
     $this->user = $this->load_user(); 
     $this->user->getUserRoles(); 
    } 

    public function index() 
    { 
     //Will only list the latest post ;) 
     if(!$this->user->hasPermission('blog_access')) 
     { 
      $array = $this->model->list_posts(); 

      if(empty($array)) 
      { 
       $this->variables(array(
        'site_title' => 'View Blog Posts', 
        'post_title' => 'Sorry but there are no posts to display' 
       )); 
      } else { 
       $this->variables(array(
        'site_title' => 'View Blog Posts', 
        'list'  => $array[0], 
        'post_title' => $array[0]['entry_title'], 
        'link'  => str_replace(' ', '_',$array[0]['entry_title']), 
       )); 
      } 
     } else { 
      $this->variables(array(
       'site_title' => 'Error :: Design Develop Realize', 
       'body'  => 'Sorry, but you do not have permission to access this', 
      )); 
     } 

     $this->parse('blog/list', $this->toParse); 
    } 

這是成員文件:

<?php 

class member extends frontController { 
    public $model; 
    public $user; 

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

     $this->model = $this->autoload_model(); 
     $this->user = $this->load_user(); 
     $this->user->getUserRoles(); 
    } 

    public function index() 
    { 
     //Will only list the latest post ;) 
     if(!$this->user->hasPermission('blog_access')) 
     { 
      //$array = $this->model->list_posts(); 

      if(empty($array)) 
      { 
       $this->variables(array(
        'site_title' => 'Design Develop Realize :: View Blog Posts', 
        'post_title' => 'Sorry but there are no posts to display' 
       )); 
      } else { 
       $this->variables(array(
        'site_title' => 'Design Develop Realize :: View Blog Posts', 
        'list'  => $array[0], 
        'post_title' => $array[0]['entry_title'], 
        'link'  => str_replace(' ', '_',$array[0]['entry_title']), 
       )); 
      } 
     } else { 
      $this->variables(array(
       'site_title' => 'Error :: Design Develop Realize', 
       'body'  => 'Sorry, but you do not have permission to access this', 
      )); 
     } 

     $this->parse('blog/list', $this->toParse); 
    } 

在成員類,如果我註釋掉$this->user = $this->load_user();然後錯誤消失! 僅供參考下面是一個函數:

protected function load_user() 
{ 
    if(!$this->loader->loaded['acl']) 
    { 
     $this->loader->loadCore('acl'); 
    } 

    return $this->loader->loaded['acl']; 
} 

任何幫助或建議將作爲我難倒不勝感激!

PS是的我有錯誤報告設置涵蓋一切,沒有它不記錄任何東西!

編輯:因爲所有的文件都要經過的index.php我已經把錯誤報告有:

<?php 
error_reporting(E_ALL); 
ini_set('date.timezone', "Europe/London"); 

require_once('system/library/loader.php'); 

$loader = new loader(); 
$loader->loadCore(array('frontController', 'routing')); 

編輯2: loadCore()低於

public function loadCore($toLoad, $params = false) 
{ 
    //important task first, check if it is more then 1 or not 
    if(is_array($toLoad)) 
    { 
     //more then one so lets go to the task! 
     foreach($toLoad as $file) 
     { 
      if(file_exists('system/library/' . $file . '.php')) 
      { 
       require_once('system/library/' . $file . '.php'); 

       if($params) 
       { 
        $this->loaded[$file] = new $file($params); 
       } else { 
        $this->loaded[$file] = new $file; 
       } 
      } else { 
       trigger_error("Core File $file does not exist"); 
      } 
     } 
    } else { 
     //Phew, less work, it is only one! 
     if(file_exists('system/library/' . $toLoad . '.php')) 
     { 
      require_once('system/library/' . $toLoad . '.php'); 

      if($params) 
      { 
       echo(__LINE__); exit; 
       $this->loaded[$toLoad] = new $toLoad($params); 
      } else { 
       $this->loaded[$toLoad] = new $toLoad; 
      } 
     } 
    } 
} 

更新:我修改了loadCore,所以如果是被調用的acl,它會使用try ... catch()並且沒有幫助,因爲它不會顯示錯誤ju st相同的鉻和IE頁

更新2:我已經說過我的主機,似乎每當這個錯誤發生,apache記錄以下(不知道爲什麼我看不到它在我的日誌副本! )

[週三02月22日8時07分11秒2012] [錯誤] [客戶93.97.245.13]過早結束腳本頭 :index.php文件

+2

你能說明你是如何設置錯誤報告的嗎?你在看哪些日誌?因爲像這樣的東西絕對應該留下痕跡的地方 – 2012-02-15 11:19:50

+0

我已經更新了問題,顯示佩卡 – 2012-02-15 11:28:13

+0

你能嘗試把的error_reporting行權違規調用的前面,以排除它被設置爲「安靜」一些呢?你能指定你在看哪些日誌嗎? – 2012-02-15 11:35:53

回答

1

「腳本標題提前結束」是內部服務器錯誤。這通常發生在腳本中斷並且在發送錯誤消息之前不發送任何HTTP標頭。這可能有幾個原因。

  • 有人可能會輸出緩衝。可能是您正在使用的服務器默認緩衝輸出。我會建議關閉output_buffering使用output_buffering = offphp.ini[docs here]

  • 確保您發送正確的HTTP報頭也

    打印 「內容類型:text/html的\ n \ n」;

上有this link幾個建議。 要了解有關此錯誤的更多信息,請致電go here

希望它有幫助

+0

它沒有完全解決它,但已經解決了另一個我不知道的問題,所以謝謝 – 2012-02-24 18:53:28

+0

@MarcTowler,很高興我可以幫助一點.... – Starx 2012-02-25 02:38:44

1

我會很感興趣地看loadCore函數內部有什麼。

您是否在任何地方使用過error_log?這可能有助於澄清這個問題。

+0

我已更新的代碼,並沒有我沒有使用error_log – 2012-02-15 15:15:47

+0

謝謝!我看到一個'echo(__ LINE__);退出;'在loadCore中。部分測試? – snoj 2012-02-15 15:23:39

+0

這是現在是的,它是有希望的幫助 – 2012-02-15 15:25:06

1

您是否在不同的瀏覽器中測試了此頁?谷歌搜索錯誤,它表明它可能是特定於Chrome的?

你對loadCore('acl')進行註釋的語句很有趣,很明顯我會從那裏開始。你確定它是通過加載程序獲取system/library/acl.php頁面的嗎?也就是說,它正在觸發loadCore()中出口下方的第2行? var_dump返回imo以確保您獲取該對象。

+0

是的,正如我所說的,我試過不同的瀏覽器,我var_dumped,它正確地獲取文件它在一個php文件中工作,但不在另一個 – 2012-02-21 21:10:53

2

您已註釋

// $陣列= $這個 - >模型 - > list_posts();

所以現在數組爲null,你要使用

'名單'=> $數組[0], 'POST_TITLE'=> $數組[0] [ 'ENTRY_TITLE'],

這肯定會產生一個錯誤。

編輯: -

我看你有沒有

'body' => 'Sorry, but you do not have permission to access this' ,)); }

也就是說在第二否則這是一個語法錯誤。並生成一個輸出。如果您已啓用,壓縮CI中的輸出,則會導致此錯誤。

+0

感謝您指出,這是相同的線被註釋掉或不,我已經更新了一個新的日誌結果從apache – 2012-02-22 21:38:29

+2

''身體'=> '對不起,但你沒有權限訪問', )); }' 逗號在末尾意味着,它期待在數組中的另一個元素。但我不確定這是否是問題。 – 2012-02-23 06:19:41

0

首先。當您的服務器在發送任何數據之前斷開連接時會產生此錯誤。 一些建議。

  • 你的代碼被打破,讓應用程序崩潰
  • 你的錯誤記錄應該由通告增強
  • 寫測試,以檢查各部件
  • ü應該啓用並使用調試器(zend_debugger,Xdebug的)
  • 後幾個連接的相關信息(例如:wget -O - --debug「URL」)

有/是一個特殊的鉻爲概率問題lem http://www.google.pl/support/forum/p/Chrome/thread?tid=3aa7b40eb01a95c8&hl=en#fid_3aa7b40eb01a95c80004ae797939c267

0

我建議檢查標籤前是否有空行。

您使用的是什麼文件名?是否有任何約定需要遵循以適合您可能使用的框架?

0

我不知道這是服務器問題,而不是代碼問題?

This thread表明您看到的服務器錯誤(500過早結束標頭)可能是由於Apache日誌太滿而需要旋轉的結果。然而,它確實可能是任何東西 - 它似乎只是簡單地表明該腳本完全不向瀏覽器返回任何輸出。

我要檢查的另一件事是文件權限,以及loadCore方法中include_once和file_exists的功能,因爲這看起來是最可能發生問題的區域,可能會導致腳本停止運行,甚至不會拋出php錯誤。

0

也許it's字符/編碼錯誤,打開這兩個文件,用記事本++,轉到編碼,然後選擇轉換爲UTF-8,保存文件,並再次測試。

祝你好運!

相關問題