我在我的项目中使用了DOMPDF,在我的系统中实现之前,我做了一些测试,但每次我运行服务时,它都会显示60秒超时,首先我创建了一个控制器:
public function invoice()
{
$data = $this->getData();
$date = date('Y-m-d');
$invoice = "2222";
$view = \View::make('pdf.invoice', compact('data', 'date', 'invoice'))->render();
$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML($view);
return $pdf->stream('invoice');
}
public function getData()
{
$data = [
'quantity' => '1' ,
'description' => 'some ramdom text',
'price' => '500',
'total' => '500'
];
return $data;
}然后添加路由:
Route::get('pdf', 'PdfController@invoice');我添加的最后一部分是视图中的文件夹,名称为pdf,文件为invoice.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Example 2</title>
<link rel="stylesheet" href="{{asset('plugins/bootstrap/css/bootstrap.css')}}">
</head>
<body>
<main>
<div id="details" class="clearfix">
<div id="invoice">
<h1>INVOICE {{ $invoice }}</h1>
<div class="date">Date of Invoice: {{ $date }}</div>
</div>
</div>
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th class="no">#</th>
<th class="desc">DESCRIPTION</th>
<th class="unit">UNIT PRICE</th>
<th class="total">TOTAL</th>
</tr>
</thead>
<tbody>
<tr>
<td class="no">{{ $data['quantity'] }}</td>
<td class="desc">{{ $data['description'] }}</td>
<td class="unit">{{ $data['price'] }}</td>
<td class="total">{{ $data['total'] }} </td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2"></td>
<td >TOTAL</td>
<td>$6,500.00</td>
</tr>
</tfoot>
</table>
</body>
<script src="{{asset('plugins/jquery/js/jquery-2.1.4.js')}}"></script>
<script src="{{asset('plugins/bootstrap/js/bootstrap.js')}}" ></script>
</html>网址:http://localhost:8000/pdf
如果有人能告诉我我的错误在哪里,我真的很感激。
发布于 2016-02-13 01:24:45
您的脚本执行了超过60秒,并被终止,并且与Laravel无关,但与php相关。默认限制为60秒,存储在php.ini文件中。要暂时延长时间限制,您可以在当前脚本中使用下面的if代码,但也要尝试优化您的脚本(如果可能)
set_time_limit(120); //120 seconds = 2 minuteRead more on php manual.
你可以执行set_time_limit(0);,这样脚本将永远运行--但是不推荐这样做,而且你的web服务器可能会发现你有一个强制的
超时(通常在5分钟左右)。您还可以使用
ini_set('max_execution_time', 120);Check ini_set.
更新
这可能是名称空间问题。尝尝这个
$pdf = PDF::loadHTML('your view here ');
return $pdf->stream();发布于 2022-02-24 09:27:24
如果你使用的是Bootstrap框架,它将会非常慢。只需删除它并使用原生css即可。
https://stackoverflow.com/questions/35368578
复制相似问题