Git Product home page Git Product logo

Comments (13)

spiritix avatar spiritix commented on September 23, 2024 1

Indeed, puppeteer resp. Chromium in general uses quite a lot of RAM. Increasing memory on the server might make it a bit faster and more stable, but it shouldn't have such a great impact.

Currently the library doesn't re-use browser sessions, as it's request based, like PHP is in general. It's not optimized for generating a huge bunch of PDF files in a row. This would be a good improvement for the future.

from php-chrome-html2pdf.

spiritix avatar spiritix commented on September 23, 2024 1

Indeed, the error isn't coming from PHP. Will have to investigate this further once I have some time. Meanwhile, I released a new version of the library containing the fix mentioned earlier.

from php-chrome-html2pdf.

spiritix avatar spiritix commented on September 23, 2024

Hi @coxfrederic,

Generally, "TimeoutError: Navigation timeout of 30000 ms exceeded" means the page took more than 30s to load and render, which is very unlikely. If the page loads fast in a browser, it should also load fast in this library.

You need to make sure that all external URLs in the HTML are accessible from the machine where you execute the library. For example, if you have a script like <script src="http://localhost/my.js"> it could actually end up in the mentioned error, since the external resource couldn't be loaded.

If that doesn't help, you can send the HTML to my email, maybe I can spot something.

from php-chrome-html2pdf.

coxfrederic avatar coxfrederic commented on September 23, 2024

Hi @spiritix ,

Thanks for your quick response.

The memory on the server is limited to 2GB and I found online that Puppeteer needs around 1GB of RAM ? So we increased the memory on the server to see if that improves things.

The external URL we will replace with images instead of using fontawesome.

I see the library is creating a new instance of a browser each time and closes it. Is that the preferred way or is there also an option to re-use the same instance? Would that improve things or actually not?

from php-chrome-html2pdf.

coxfrederic avatar coxfrederic commented on September 23, 2024

Currently our problem seems solved by upgrading RAM, but an option for the library to re-use the same instance for X amount of time would indeed be very nice in some use cases. I'll keep an eye on it and will close this issue for now.

Anyway, awesome work on this library, and thanks for your help!

from php-chrome-html2pdf.

coxfrederic avatar coxfrederic commented on September 23, 2024

I'm reopening this issue since I'm getting the same error for a page that loads a lot of content. In my browser it takes around 65-70 seconds.

I have tried setting the timeout option to 300 seconds but it doesn't have any effect. I'm still getting the TimeoutError: Navigation timeout of 30000 ms exceeded after 30 seconds.

How come the timeout value is not taken into account? Any solution to this problem?

from php-chrome-html2pdf.

spiritix avatar spiritix commented on September 23, 2024

Can you try to open the website directly in Puppeter and convert it to PDF, to see how long it takes to load? Something like this should do it:

const puppeteer = require('puppeteer')
 
async function printPDF() {
  const browser = await puppeteer.launch({ headless: true });
  const page = await browser.newPage();
  await page.goto('https://url.com', {waitUntil: 'networkidle0'});
  const pdf = await page.pdf({ format: 'A4' });
 
  await browser.close();
  return pdf
})

from php-chrome-html2pdf.

coxfrederic avatar coxfrederic commented on September 23, 2024

It takes around 65 seconds to load

from php-chrome-html2pdf.

spiritix avatar spiritix commented on September 23, 2024

@coxfrederic Thanks, this confirms that it's an issue with Puppeter. Maybe this fix helps? puppeteer/puppeteer#1846 (comment)

If so, I can implement it in this library

from php-chrome-html2pdf.

coxfrederic avatar coxfrederic commented on September 23, 2024

Yes! That would be amazing if you could implement it

from php-chrome-html2pdf.

coxfrederic avatar coxfrederic commented on September 23, 2024

What I don't understand though, the timeout is still at 30seconds. So it is ignored?
I don't see how this is related to puppeteer/puppeteer#1846 (comment) that the error fires after 30 seconds even though I specified the timeout to 300 seconds.

from php-chrome-html2pdf.

spiritix avatar spiritix commented on September 23, 2024

Indeed, those issues are not related. I suspect that the timeout is coming from PHP and not from Puppeter, because in PHP the default timeout is also 30 seconds.

from php-chrome-html2pdf.

coxfrederic avatar coxfrederic commented on September 23, 2024

Based on the error I do not believe it is a PHP timeout.

TimeoutError: Navigation timeout of 30000 ms exceeded
at /var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/LifecycleWatcher.js:100:111
at async DOMWorld.setContent (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/DOMWorld.js:152:23)
at async Page.setContent (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/Page.js:482:9)
at async Converter._convert (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:76:9)
at async Converter.run (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:37:24)
at async /var/puntoo/vendor/spiritix/php-chrome-html2pdf/index.js:23:20
-- ASYNC --
at Frame. (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/helper.js:94:19)
at Page.setContent (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/Page.js:482:46)
at Page. (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/helper.js:95:27)
at Converter._setHtml (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:88:21)
at Converter._convert (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:76:20)
at Converter.run (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:37:35)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /var/puntoo/vendor/spiritix/php-chrome-html2pdf/index.js:23:20

It is thrown in

public function convert(): OutputInterface
{
$result = ProcessUtil::executeShellCommand($this->buildCommand(), $this->input->getHtml());
if (strpos(mb_strtolower($result['error']), 'error') !== false) {
throw new ConverterException('Binary error: ' . $result['error']);
}

from php-chrome-html2pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.