首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel 5 barryvdh/laravel-dompdf超时

Laravel 5 barryvdh/laravel-dompdf超时
EN

Stack Overflow用户
提问于 2016-02-13 01:19:11
回答 2查看 5.2K关注 0票数 1

我在我的项目中使用了DOMPDF,在我的系统中实现之前,我做了一些测试,但每次我运行服务时,它都会显示60秒超时,首先我创建了一个控制器:

代码语言:javascript
复制
 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;
    }

然后添加路由:

代码语言:javascript
复制
Route::get('pdf', 'PdfController@invoice');

我添加的最后一部分是视图中的文件夹,名称为pdf,文件为invoice.blade.php:

代码语言:javascript
复制
<!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

如果有人能告诉我我的错误在哪里,我真的很感激。

EN

回答 2

Stack Overflow用户

发布于 2016-02-13 01:24:45

您的脚本执行了超过60秒,并被终止,并且与Laravel无关,但与php相关。默认限制为60秒,存储在php.ini文件中。要暂时延长时间限制,您可以在当前脚本中使用下面的if代码,但也要尝试优化您的脚本(如果可能)

代码语言:javascript
复制
set_time_limit(120); //120 seconds = 2 minute

Read more on php manual.

你可以执行set_time_limit(0);,这样脚本将永远运行--但是不推荐这样做,而且你的web服务器可能会发现你有一个强制的

超时(通常在5分钟左右)。您还可以使用

代码语言:javascript
复制
ini_set('max_execution_time', 120);

Check ini_set.

更新

这可能是名称空间问题。尝尝这个

代码语言:javascript
复制
$pdf = PDF::loadHTML('your view here ');
    return $pdf->stream();
票数 0
EN

Stack Overflow用户

发布于 2022-02-24 09:27:24

如果你使用的是Bootstrap框架,它将会非常慢。只需删除它并使用原生css即可。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35368578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档