ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php – 如何调试“最大执行时间”致命错误?

2019-05-30 16:16:46  阅读:162  来源: 互联网

标签:php zend-framework zend-acl


我正在尝试在我的应用程序中使用Zend_acl.我遵循了“Zend Framework in action”一书.
我添加了这个助手:

<?php
/**
* Zend Framework
*
* LICENSE "removed for clarity"
*

/** Zend_Controller_Action_Helper_Abstract */
require_once 'Zend/Controller/Action/Helper/Abstract.php';



class Bravo_Controller_Action_Helper_Acl extends Zend_Controller_Action_Helper_Abstract
{

    protected $_action;

    protected $_auth;

    protected $_acl;

    protected $_controllerName;

    public function __construct(Zend_View_Interface $view = null, array $options = array())
    {
        $this->_auth = Zend_Auth::getInstance();
        $this->_acl = $options['acl'];
        //var_dump($this->_acl);die();
    }

    public function init()
    {
        $this->_action = $this->getActionController();

        // add resource for this controller
        $controller = $this->_action->getRequest()->getControllerName();
        if(!$this->_acl->has($controller)) {
            $this->_acl->add(new Zend_Acl_Resource($controller));
        }

    }

    public function preDispatch()
    {
        $role = 'guest';
        if ($this->_auth->hasIdentity()) {
            $user = $this->_auth->getIdentity();
            if(is_object($user)) {
                $role = $this->_auth->getIdentity()->getUral()->getUralAccessNbr();
            }
        }

        $request = $this->_action->getRequest();
        $controller = $request->getControllerName();
        $action = $request->getActionName();
        $module = $request->getModuleName();
        $this->_controllerName = $controller;

        $resource = $controller;
        $privilege = $action;

        if (!$this->_acl->has($resource)) {
            $resource = null;
        }

        //** EDIT: During my test, the user isn't allowed. I'm now suspecting the 4 requests setting to be wrong.
        if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
            $request->setModuleName('default');
            $request->setControllerName('login');
            $request->setActionName('login');
            $request->setDispatched(false);            
        }

    }


    public function allow($roles = null, $actions = null)
    {
        $resource = $this->_controllerName;
        $this->_acl->allow($roles, $resource, $actions);
        return $this;
    }

    public function deny($roles = null, $actions = null)
    {
        $resource = $this->_controllerName;
        $this->_acl->deny($roles, $resource, $actions);
       return $this;
    }

}

和bootstrap:

<?php

class Agenda_Bootstrap extends Zend_Application_Module_Bootstrap
{

    protected function _initAcl()
    {

        // acl action helper
        $acl = new Bravo_Acl_Acl();
        $aclHelper = new Bravo_Controller_Action_Helper_Acl(null, array('acl' => $acl));
        Zend_Controller_Action_HelperBroker::addHelper($aclHelper);
    }
}

Helper不在控制器中使用.我尝试了我的应用程序,看看是否一切都正确,我收到了这个错误:

Fatal error: Maximum execution time of 30 seconds exceeded in /usr/share/php/ZendFramework-1.11.11/Zend/Filter/PregReplace.php on line 171

使用此调用堆栈:

Call Stack
#   Time    Memory  Function                                                Location
1   0.0001  314556  {main}( )                                               ../index.php:0
2   0.3275  2039356 Zend_Application->run( )                                ../index.php:29
3   0.3275  2039356 Zend_Application_Bootstrap_Bootstrap->run( )                ../Application.php:366
4   0.3276  2039412 Zend_Controller_Front->dispatch( )                      ../Bootstrap.php:97
5   31.7462 4813252 Zend_Controller_Dispatcher_Standard->dispatch( )        ../Front.php:954
6   31.7470 4813944 Zend_Controller_Action->__construct( )                      ../Standard.php:268
7   31.7470 4814144 Zend_Controller_Action_HelperBroker->__construct( )     ../Action.php:132
8   31.7472 4814924 Zend_Controller_Action_Helper_ViewRenderer->init( )     ../HelperBroker.php:253
9   31.7472 4814924 Zend_Controller_Action_Helper_ViewRenderer->initView( )     ../ViewRenderer.php:516
10  31.7473 4815260 Zend_Controller_Action_Helper_ViewRenderer->_getBasePath( ) ../ViewRenderer.php:469
11  31.7478 4815628 Zend_Filter_Inflector->filter( )                        ../ViewRenderer.php:393
12  31.7489 4816768 Zend_Filter_Word_CamelCaseToSeparator->filter( )        ../Inflector.php:473
13  31.7489 4816768 Zend_Filter_PregReplace->filter( )               ../CamelCaseToSeparator.php:46

我试图增加max_execution_time,但它始终是相同的:前四个堆栈仍然没有变化,第五个反映了max_execution_time(30秒=> 31.7462,40秒=> 42.6546等等)

所以我怀疑Zend_Controller_Front-> dispatch()是我的问题来源,但为什么总是需要最长时间?我有点困惑.有人知道我应该在哪里挖掘?

编辑:我在调试中更进一步.我现在怀疑当不允许用户时,我的助手中的4个请求设置错误.我也编辑了帮助程序代码并添加了注释.

编辑2:帕特里克,你是对的!我重新检查了,我陷入了无限循环:不要有访问登录页面=> go-to-login-page :-D今天多么浪费时间……无论如何,它结束了,谢谢大家.

解决方法:

if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
    $request->setModuleName('default');
    $request->setControllerName('login');
    $request->setActionName('login');
    $request->setDispatched(false);            
}

您确定无论角色如何,您始终都有权访问登录控制器吗?

无论如何,听起来你最终陷入无限循环,ZF的调度循环永远不会完成.

标签:php,zend-framework,zend-acl
来源: https://codeday.me/bug/20190530/1184436.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有