PHP 执行超时在每个带有数据库调用的 Laravel请求上


php execution timeout on every laravel request with database call

我使用 xampp 设置了本地开发环境,并且正在使用 laravel 5.2 和 php5.6.3。在没有数据库操作的情况下发出路由请求运行没有任何问题,但尝试使用雄辩的模型访问数据库会导致

Maximum execution time of 60 seconds exceeded

在执行数据库操作的不同点。这是错误日志

[2016-04-25 02:57:56] local.ERROR: exception 'Symfony'Component'Debug'Exception'FatalErrorException' with message 'Maximum execution time of 60 seconds exceeded' in C:'xampp'htdocs'pscosmetics'vendor'laravel'framework'src'Illuminate'Database'Eloquent'Model.php:539
Stack trace:
#0 {main}  
[2016-04-25 03:05:57] local.ERROR: exception 'Symfony'Component'Debug'Exception'FatalErrorException' with message 'Maximum execution time of 60 seconds exceeded' in C:'xampp'htdocs'pscosmetics'vendor'laravel'framework'src'Illuminate'Support'Str.php:89
Stack trace:
#0 {main}  
[2016-04-25 03:08:51] local.ERROR: exception 'Symfony'Component'Debug'Exception'FatalErrorException' with message 'Maximum execution time of 60 seconds exceeded' in C:'xampp'htdocs'pscosmetics'vendor'laravel'framework'src'Illuminate'Database'Query'Grammars'Grammar.php:834
Stack trace:
#0 {main}  
[2016-04-25 03:11:04] local.ERROR: exception 'Symfony'Component'Debug'Exception'FatalErrorException' with message 'Maximum execution time of 60 seconds exceeded' in C:'xampp'htdocs'pscosmetics'vendor'laravel'framework'src'Illuminate'Database'Eloquent'Model.php:539
Stack trace:
#0 {main}  
[2016-04-25 03:35:59] local.ERROR: exception 'Symfony'Component'Debug'Exception'FatalErrorException' with message 'Maximum execution time of 60 seconds exceeded' in C:'xampp'htdocs'pscosmetics'vendor'laravel'framework'src'Illuminate'Database'Eloquent'Relations'Relation.php:204
Stack trace:
#0 {main}  
[2016-04-25 03:40:42] local.ERROR: exception 'Symfony'Component'Debug'Exception'FatalErrorException' with message 'Maximum execution time of 60 seconds exceeded' in C:'xampp'htdocs'pscosmetics'vendor'laravel'framework'src'Illuminate'Database'Query'Grammars'Grammar.php:834
Stack trace:
#0 {main}  

Trying the same db operation using vanilla php and PDO works without a hitch, phpMyadmin works ok.
What could cause this sort of issue?.

经过数小时的挖掘错误堆栈跟踪,我发现问题出在 Eloquent 急切加载上。

<?php
namespace App'Entities;
use Illuminate'Database'Eloquent'Model;
class Category extends Model {
    protected $fillable = ['parent_id', 'name', 'slug', 'description', 'keywords'];
   /**
   This is what was causing the timeouts as it had it's own nested relationships
    */
   protected $with = ['products']; 
    public function products() {
        return $this->hasMany('App'Entities'Product', 'category_id');
    }
}