Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML2PDF 504 Gateway Timeout #464

Open
mittultechnobrave opened this Issue Apr 9, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@mittultechnobrave
Copy link

commented Apr 9, 2019

I am trying to convert HTML 2 PDF with this library and its converting fine as per my expectations.

However, When I convert with more data, its giving me an error saying 504 Gateway Timeout. Here is the error screenshot what I am getting.

enter image description here

In local server its working fine. I have the same server in my local and my live (Linux). The only problem is I am getting when I try to produce PDF with long data on live server.

I researched and found out that to increase php execution time and other settings. Hence I try to put below code in my .php file.

ini_set('max_execution_time', 60000);
ini_set('post_max_size','128M');
ini_set('upload_max_filesize','128M');

I even try to set max_execution_time to 0 and -1 but yet its not working for me. After setting this values, I even printed the updated values with phpinfo(), the values are overwriting but I am having the same 502 Gateway timeout error. Here is small chunk of code just in case you want to see.

<?php

ini_set('max_execution_time', 60000);
ini_set('post_max_size','20M');
ini_set('upload_max_filesize','8M');

require_once dirname(__FILE__) . '/vendor/autoload.php';
require_once dirname(__FILE__) . '/templateInfo.php';

use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
use technobrave\brochuresettings\Models\Brochuresettings as BS;
use Technobrave\Transactions\Models\Transactions as TR;
use Technobrave\Offices\Models\Offices;
use technobrave\themesettings\Models\ThemeSetting as TS;
use Technobrave\Team\Models\Team;



class generateTemplate {



   	public $theme = "";

    public $theme_settings = array();

    public function __construct($templateId, $resolution , $theme ,$pdf_sections = array(),$openFile = false, $finalPdfFile = null) {
        
        $this->getBrochureTransactionData = BS::first();
        $this->getPdfSection = $pdf_sections;
        $this->theme_settings = TS::first();
        $this->theme = $theme;
        $this->baseUrl = url(Config::get('cms'));
        $this->teamPageName = $this->baseUrl . '/our-team';
        $this->capabilitiesPageName = $this->baseUrl . '/capabilities';
        $this->getFooterText = $this->getFooterText();
        $getTeamId = (isset($_GET['teamId']) && !empty($_GET['teamId'])) ? $_GET['teamId'] : "";
	    $this->uniquePath = __DIR__ . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
	    $templatePath = __DIR__ . DIRECTORY_SEPARATOR . 'regency_template' . DIRECTORY_SEPARATOR . $getTeamId . DIRECTORY_SEPARATOR . $templateId . '.php';
	    $templateInfoText = new templateInfo($templateId, $this->uniquePath, $getTeamId);
	    $this->customImagePath = $this->uniquePath;

        foreach ($templateInfoText->defaultValues as $key => $value) {
            $this->{$key} = $value;
        }
 
        
	    $template = file_get_contents($templatePath);

	
        
        try 
        {

            $html2pdf = new Html2Pdf('L','A4', 'en', true, 'UTF-8', array(0, 0, 0, 0));
            $html2pdf->Addfont('perpetua');
            $html2pdf->Addfont('montserratbold');
            $html2pdf->Addfont('montserratmedium');
            $html2pdf->Addfont('montserratregular');
            $html2pdf->Addfont('montserratsembold');
            $html2pdf->Addfont('montserratitalic');
            $html2pdf->writeHTML($template, false);
            
            $html2pdf->Output('regency_corporate_brochure.pdf', 'D');
            

        } catch (Html2PdfException $e) {
            $formatter = new ExceptionFormater($e);
            echo $formatter->getHtmlMessage();
        }
        
    }
}

I tried to preview how my HTML is generating and its generating without any error.

$html2pdf->writeHTML($template, true); 

So basically I am facing server issue here as per my understanding so far.

Can someone guide me what should I do from here on to solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.