2015-09-07 13:12:23 2972次浏览 2条回答 1 悬赏 100 金钱

virtual Box 虚拟机 设置1G内存, centos 6.7 nginx 1.8.0 php 5.5.27 MariaDB 5.5.44

AccountForm

/**
     * Saves new account settings.
     *
     * @return bool
     */
    public function save()
    {
        if ($this->validate()) {
            if ($this->new_password) {
                $this->user->password = $this->new_password;
            }
            return $this->user->save();
        }
        return false;
    }

controller

$model = new AccountForm();
        if ($model->load(yii::$app->request->post())&&$model->save()) {
            //.......
        }

error info

PHP Fatal Error 'yii\base\ErrorException' with message 'Maximum execution time of 5 seconds exceeded' 
in /home/wwwroot/www.yiitest.com/vendor/yiisoft/yii2/base/Security.php:565
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
  • 回答于 2015-09-07 13:50 举报

    看字面意思是执行5秒后超时了~
    确定可以连上数据库?确定数据库正常?你的user模型是自定义的吧?确定代码正确?

    2 条回复
    回复于 2015-09-07 13:57 回复

    谢谢回答。
    1.确定可以连上数据库 因为要修改密码 先要登录。 当然除了登录其他的操作一样都有数据库的部分。都是正常的。

    
    <?php
    /**
     * @Author: forecho
     * @Date:   2015-01-30 23:01:28
     * @Last Modified by:   forecho
     * @Last Modified time: 2015-01-31 21:08:34
     */
    namespace common\modules\account\models;
    
    use yii\base\Model;
    
    class AccountForm extends Model
    {
        /** @var string */
        public $email;
        /** @var string */
        public $username;
        /** @var string */
        public $truename;
        /** @var string */
        public $new_password;
        /** @var string */
        public $current_password;
        private $_user;
    
        /** @return User */
        public function getUser()
        {
            if ($this->_user == null) {
                $this->_user = \Yii::$app->user->identity;
            }
            return $this->_user;
        }
    
        /** @inheritdoc */
        public function __construct()
        {
            $this->setAttributes([
                'username' => $this->user->username,
                'email' => $this->user->email,
                'truename' => $this->user->truename,
            ], false);
            parent::__construct();
        }
    
        /** @inheritdoc */
        public function rules()
        {
            return [
                [['username', 'email', 'current_password', 'truename'], 'required'],
                [['username', 'email'], 'filter', 'filter' => 'trim'],
                ['username', 'match', 'pattern' => '/^[a-zA-Z]\w+$/'],
                ['username', 'string', 'min' => 2, 'max' => 20],
                ['truename', 'string', 'min' => 2, 'max' => 40],
                ['email', 'email'],
                [['email', 'username'], 'unique', 'when' => function ($model, $attribute) {
                    return $this->user->$attribute != $model->$attribute;
                }, 'targetClass' => \yii::$app->user->identityClass, 'message' => '此{attribute}已经被使用。'],
                ['new_password', 'string', 'min' => 6],
                ['current_password', function ($attr) {
                    if (!\Yii::$app->security->validatePassword($this->$attr, $this->user->password_hash)) {
                        $this->addError($attr, '当前密码是输入错误');
                    }
                }]
            ];
        }
    
        /** @inheritdoc */
        public function attributeLabels()
        {
            return [
                'email' => '电子邮件',
                'username' => '用户名',
                'truename' => '姓名',
                'new_password' => '新密码',
                'current_password' => '当前密码',
            ];
        }
    
        /** @inheritdoc */
        public function formName()
        {
            return 'account-form';
        }
    
        /**
         * Saves new account settings.
         *
         * @return bool
         */
        public function save()
        {
            if ($this->validate()) {
                $this->user->username = $this->username;
                $this->user->truename = $this->truename;
                $this->user->email = $this->email;
                // 新密码没填写 则为不修改密码
                if ($this->new_password) {
                    $this->user->password = $this->new_password;
                }
                return $this->user->save();
            }
            return false;
        }
    }
    
    
    回复于 2015-09-07 14:09 回复

    貌似是生成加密时超时了,帮不到你了~

  • 回答于 2015-09-07 16:06 举报

    高能运算, 超时了.

    一方面 归功于虚拟机性能, 另一方面 代码也的确存在一点小问题.

     // 新密码没填写 则为不修改密码
     if ($this->new_password) {
         $this->user->password = $this->new_password;
     }
    

    不修改密码的情况下, $this->user->password_hash 是个长串, 保存的时候会再此基础上进行 password_hash 运算

    解决问题的话 着眼于getUser()方法.

    因为 Yii::$app->user->identity->isNewRecord == true

您需要登录后才可以回答。登录 | 立即注册
xjdata
CEO

xjdata

注册时间:2011-12-07
最后登录:2024-05-05
在线时长:112小时38分
  • 粉丝23
  • 金钱14169
  • 威望75
  • 积分16039

热门问题