2012-02-15 72 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,保存文件,并再次测试。

祝你好运!

相关问题