gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:05:53 25 4
gpt4 key购买 nike

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

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');
}
}

关于每个带有数据库调用的 Laravel 请求的 php 执行超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36827781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com