Php 使用从控制器传递的数据渲染任何视图时,Laravel 5超时
在我的应用程序中,我总是能够像通常使用Php 使用从控制器传递的数据渲染任何视图时,Laravel 5超时,php,laravel,laravel-5,Php,Laravel,Laravel 5,在我的应用程序中,我总是能够像通常使用view('myView',compact('data'))一样将数据传递到任何视图。到今天为止,我尝试以这种方式渲染的任何视图都会超时。我得到的错误超过了中的最大执行时间120秒。我尝试增加php.ini和httpd.conf超时时间,但没有超时。这真的很奇怪,对我来说毫无意义,因为我总是能够几乎立即呈现我的视图,即使是从数据库检索15k+记录并像往常一样将它们传递给视图时也是如此 我的控制器: use App\Product; use Illuminat
view('myView',compact('data'))一样将数据传递到任何视图代码>。到今天为止,我尝试以这种方式渲染的任何视图都会超时。我得到的错误超过了中的最大执行时间120秒代码>。我尝试增加php.ini
和httpd.conf
超时时间,但没有超时。这真的很奇怪,对我来说毫无意义,因为我总是能够几乎立即呈现我的视图,即使是从数据库检索15k+记录并像往常一样将它们传递给视图时也是如此
我的控制器:
use App\Product;
use Illuminate\Support\Facades\Session;
class HomeController extends Controller {
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
//the controller is normally like this
//$products = Product::paginate(16);
//return view('home', compact('products'));
//I'm testing with these 2 lines below but no cigar.
$product = Product::wherePid(303)->first();
return view('test', compact('product'));
}
}
我创建的测试视图:
use App\Product;
use Illuminate\Support\Facades\Session;
class HomeController extends Controller {
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
//the controller is normally like this
//$products = Product::paginate(16);
//return view('home', compact('products'));
//I'm testing with these 2 lines below but no cigar.
$product = Product::wherePid(303)->first();
return view('test', compact('product'));
}
}
@extends('app')
@section('content')
{{ $product->name }}
@stop
@extends('app')
<pre>{{ var_dump(Session::all())}}</pre>
@section('content')
<div class="row">
@foreach($products as $product)
<div class="col-xs-6 col-sm-3 col-lg-3 col-md-3">
<?php
if($product->img[7] == 'm' || $product->img[7] == 'M') echo "<div class='continenteIcon'></div>";
else echo "<div class='jumboIcon'></div>";
?>
<div class="thumbnail">
<a href="products/{{$product->pid}}"><img src="{{$product->img}}" title="
<?php
if($product->dispname != '') echo $product->dispname;
else echo $product->name;
?> ">
</a>
<div class="caption">
<h4>
<a style="text-decoration:none;" class="wordwrap" title="
<?php
if($product->dispname != '')
echo $product->dispname;
else echo $product->name;
?>" href="products/{{$product->pid}}">
<?php
if($product->dispname != '')
echo $product->dispname;
else echo $product->name;?>
</a>
</h4>
<p>{{$product->brand}}</p>
<span class="pull-right price">€{{$product->price}}</span>
<br/>
<span class="pull-right ppk">€{{round($product->pricekilo, 2)}} Kg, L ou Und</span>
</div>
<div class="ratings">
<p class="pull-right"> {{-- # review--}}</p>
<p>
<form method="post" action="add/{{$product->pid}}">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<button title="Adicionar ao carrinho" type="submit" class="btn btn-success">
<i class="fa fa-shopping-cart"></i>
</button>
</form>
<form method="post" action="products/related/{{$product->pid}}">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<button title="Ver artigos semelhantes" style="position:relative; bottom:35px;" type="submit" class="btn btn-info pull-right">
<i class="fa fa-search"></i>
</button>
</form>
</p>
</div>
</div>
</div>
@endforeach
</div>
<div class="row">
{!! $products->render() !!}
</div>
<div class="row">
<div class="pull-right">
* Preço por unidade, Litro ou Kilograma
</div>
@stop
@section('scripts')
@stop
我的应用程序视图:
use App\Product;
use Illuminate\Support\Facades\Session;
class HomeController extends Controller {
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
//the controller is normally like this
//$products = Product::paginate(16);
//return view('home', compact('products'));
//I'm testing with these 2 lines below but no cigar.
$product = Product::wherePid(303)->first();
return view('test', compact('product'));
}
}
@extends('app')
@section('content')
{{ $product->name }}
@stop
@extends('app')
<pre>{{ var_dump(Session::all())}}</pre>
@section('content')
<div class="row">
@foreach($products as $product)
<div class="col-xs-6 col-sm-3 col-lg-3 col-md-3">
<?php
if($product->img[7] == 'm' || $product->img[7] == 'M') echo "<div class='continenteIcon'></div>";
else echo "<div class='jumboIcon'></div>";
?>
<div class="thumbnail">
<a href="products/{{$product->pid}}"><img src="{{$product->img}}" title="
<?php
if($product->dispname != '') echo $product->dispname;
else echo $product->name;
?> ">
</a>
<div class="caption">
<h4>
<a style="text-decoration:none;" class="wordwrap" title="
<?php
if($product->dispname != '')
echo $product->dispname;
else echo $product->name;
?>" href="products/{{$product->pid}}">
<?php
if($product->dispname != '')
echo $product->dispname;
else echo $product->name;?>
</a>
</h4>
<p>{{$product->brand}}</p>
<span class="pull-right price">€{{$product->price}}</span>
<br/>
<span class="pull-right ppk">€{{round($product->pricekilo, 2)}} Kg, L ou Und</span>
</div>
<div class="ratings">
<p class="pull-right"> {{-- # review--}}</p>
<p>
<form method="post" action="add/{{$product->pid}}">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<button title="Adicionar ao carrinho" type="submit" class="btn btn-success">
<i class="fa fa-shopping-cart"></i>
</button>
</form>
<form method="post" action="products/related/{{$product->pid}}">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<button title="Ver artigos semelhantes" style="position:relative; bottom:35px;" type="submit" class="btn btn-info pull-right">
<i class="fa fa-search"></i>
</button>
</form>
</p>
</div>
</div>
</div>
@endforeach
</div>
<div class="row">
{!! $products->render() !!}
</div>
<div class="row">
<div class="pull-right">
* Preço por unidade, Litro ou Kilograma
</div>
@stop
@section('scripts')
@stop
这很快,就像过去一样。我所说的快速是指不到1秒就能找到我所需要的一切。但是如果我用
User::chunk(200, function($users)
{
foreach ($users as $user)
{
//
}
});
一切都暂停了,我得到了500分(我检查过,页面停止加载后,请求状态为500)看起来您可能请求了太多的记录,这可能使用了太多的RAM。我将使用chunk命令帮助您管理您请求的金额
例如:
@extends('app')
@section('content')
<div class="row">
@foreach($products as $product)
@endforeach
</div>
@stop
首先检查日志。
下一步尝试dd($product)
下一步,如果您尝试使用最后两行渲染视图(获取第一条记录),请从模板中删除分页。
将模板清洁至最低限度,例如:
$size = Session::get('size');
...
<input type="text" value="'.Session::get($item).'">
...
@extends('app')
@节(“内容”)
@foreach($products as$product)
@endforeach
@停止
我刚把它整理好。问题出现在app.blade.php中的以下代码块中
$size=Session::get('size');
...
...
我在处理现有会议的数据,一切正常。我以为我做得对。我没有。不是偶然的:)
假设是所有错误的根源
用if(Session::has('size')包围了整个区块,一切都像往常一样快速、平稳运行。
use App\Product;
use Illuminate\Support\Facades\Session;
class HomeController extends Controller {
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
//the controller is normally like this
//$products = Product::paginate(16);
//return view('home', compact('products'));
//I'm testing with these 2 lines below but no cigar.
$product = Product::wherePid(303)->first();
return view('test', compact('product'));
}
}
感谢@Pyton为我指出了正确的方向,并感谢大家的贡献。如果你查看他的控制器,你会发现他目前只需要1条记录。是的。正是@BrokenBinary所说的。而且,这以前一直有效。从昨天起,就不再有效了。你的mysql正在运行吗?是的,一切正常正在运行。我忘记添加重要的细节:如果我回显查询结果,并且不呈现视图$products=Product::paginate(16);dd($products);//返回视图('home',compact('products'));这很快,就像过去一样。所谓快,我的意思是检索我需要的所有内容只需不到1秒。但是如果我使用返回视图(“主视图”、压缩视图(“产品”)呈现视图;所有内容都会暂停,我得到500分(我使用Fiddler2进行了检查,页面停止加载后,请求状态为500)我会检查那些日志,看看是否找到了什么,谢谢。同时,我编辑了上面的问题,添加了与你的答案相关的更多细节。仍然不行。很遗憾,清理模板并按照你说的做没有帮助。我已经试过了。这个问题肯定与渲染视图有关。我会深入研究这些日志,看看是否找到任何clue、 多谢各位