【发布时间】:2014-01-11 07:36:56
【问题描述】:
我正在使用带有 PHP 5.4.21 标准 AMI 的 Amazon Linux 64 位在 Amazon Elastic Beanstalk 上运行 Laravel 4.0 应用程序。
每当 git aws.push 完成或 Amazon 的默认每日 cron 作业运行(这会导致 Apache 重新启动)时,我的应用程序会突然在基于 Eloquent 的模型创建调用中出现异常,直到我重新启动 Apache,有时会出现 1-2 次。此后,服务器将正常运行,直到下次 Apache 重启(通过日常作业或 git push 等)
[2013-12-22 19:34:52] log.ERROR: Exception in orderProcessor->process:
exception 'ErrorException' with message 'Undefined property:
MyApp\Store\Order::$attributes' in /v/a/c/bootstrap/compiled.php:6266
Stack trace:
#0 /v/a/c/bootstrap/compiled.php(6266): Illuminate\Exception\Handler->handleError(8, 'Undefined prope...', '/v/a/c...', 6266, Array)
#1 /v/a/c/bootstrap/compiled.php(6461): Illuminate\Database\Eloquent\Model->getAttribute('attributes')
#2 /v/a/c/bootstrap/compiled.php(6379): Illuminate\Database\Eloquent\Model->__get('attributes')
#3 /v/a/c/bootstrap/compiled.php(5530): Illuminate\Database\Eloquent\Model->syncOriginal()
#4 /v/a/c/bootstrap/compiled.php(5589): Illuminate\Database\Eloquent\Model->__construct(Array)
#5 /v/a/c/app/MyApp/Store/Repositories/EloquentOrderRepository.php(62): Illuminate\Database\Eloquent\Model::create(Array)
#6 /v/a/c/app/MyApp/Store/OrderProcessor.php(65): MyApp\Store\Repositories\EloquentOrderRepository->create(Array)
#7 /v/a/c/app/controllers/StoreController.php(122): MyApp\Store\OrderProcessor->process(Object(MyApp\User), Object(MyApp\Store\Cart))
... controller and route calls ...
/v/a/c = /var/app/current 为简洁起见。 MyApp\Store\Order 扩展 Eloquent。
我真的不知道如何诊断并最终解决这个问题,正在寻求建议。
更新:我删除了下面请求的调用函数,因为它们似乎不相关。他们通过了所有测试,并成功处理了数千个订单。至少在另一个基于 Eloquent 的模型(即MyApp\User)上调用 create() 时也会发生这种情况,直到 Apache 重新启动 1-2 次。
【问题讨论】:
-
可以发
process的方法吗?这不是一个抛出异常吗?您是否调查过谁是该方法的调用者? -
异常发生在 Laravel 的 Model 类中,在 getAttribute() 函数中,特别是对 array_key_exists($key, $this->attributes) 的调用。 $this->attributes,不知何故不存在,即使它在类中初始化为空数组。
标签: amazon-web-services amazon-ec2 laravel laravel-4 amazon-elastic-beanstalk