【问题标题】:Method crashes server (homested; laravel)方法使服务器崩溃(托管;laravel)
【发布时间】:2014-12-28 18:17:57
【问题描述】:

我正在使用宅基地。我有这个代码

$researches = Auth::user()->load(['researches' => function ($q)
    {
        $q->orderBy('situational', 'desc');
        $q->orderBy('id', 'asc');
        $q->with('research_type');
    }])->researches;

    $researches = FormatController::sort($researches);
    dd($researches);

当我运行此程序时,页面无休止地加载,并以“网关 - 超时”结束,我必须重新启动宅基地,因为没有任何效果了。

在 FormatController 中运行排序方法后崩溃。它看起来像这样:

public static function sort($values, $key = 'id')
{
    $sorted = [];
    foreach ($values as $v)
    {
        $sorted[$v->$key] = $v;
    }
    return $sorted;
}

我不知道它为什么会崩溃。这个方法在这部分代码之前用过几次,效果很好。

如果我在 return 语句之前进行 die-dump,我会得到我想要的数组

有什么想法吗?

【问题讨论】:

  • 当您说崩溃时,您的意思是 Web 服务器本身崩溃(即 Apache segfault)还是 PHP 产生了致命错误?
  • 好吧,我不确定。它加载了很长一段时间,给了我一个“网关 - 超时”错误,然后我尝试加载的每个页面都做同样的事情(尽管它们在我从上面运行脚本之前工作)。
  • $sorted[$v->$key] = $v;你在这里做什么?
  • 我使用研究的“id”属性作为数组的键。这样我就可以访问我的研究,例如“$researches[$anyResearchId]”。如果我不这样做,键就会从 0 开始并向上计数。因此,我无法访问特定研究
  • 如果我不使用Auth::user()->load 而是使用User::with 它可以工作。我不知道为什么,因为Auth:user() 只是用户对象,就像我用User::find(id) 得到的对象一样

标签: php crash homestead


【解决方案1】:

好的,我不知道为什么,但我找到了解决方案:

在我发布这个脚本之后,我输入了这个:

<? $research_type = 0; ?>

我改成

<?php $research_type = 0; ?>

这对我有用。有人知道为什么吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 2023-03-29
    • 1970-01-01
    • 2015-10-26
    • 2022-09-29
    • 2023-02-23
    • 1970-01-01
    相关资源
    最近更新 更多