daudmalik06/PhpChromeToPdf

PhpChromeToPdf Timing Out

ZachHandley opened this issue · 16 comments

Hey,

Followed install instructions but my web server times out before the application returns a response. I'm only loading ~4 external resources (all on my web server), and I'm not doing anything crazy, so it should work

Any thought as to why it would return that?

Thanks

  • Zach

Hello Zach,
can you provide some more information , any POC ?, or how are you using this package?
thanks

please try that with very simple html page like hey
and check if it takes time or not ,
but if it has problem with memory there should be an error ,
and also make sure you have installed the chrome properly and it's working without this package ,

e.g
chrome --headless --disable-gpu --print-to-pdf=github.pdf https://github.com/

I believe that it's google-chrome right? And has the code been updated to reflect Chrome's new bug with headless mode? It no longer allows from root if --no-sandbox is not enabled so that could be it too

karma-runner/karma-chrome-launcher#158

yeah that's google-chrome , and did you try to run that above command from shell?
try with or without that sandbox flag and let me know if that works,

in case it works try passing that argument to chromePdf as following

$chrome->setArgument('--no-sandbox','')

I tried it in my console for github and it worked flawlessly, about 4 seconds, but in browser even with --no-sandbox it still doesn't work

$Chrome = new Chrome(NULL, '/usr/bin/google-chrome');
          $Chrome->setWindowSize($width=1024, $height=768);
          $Chrome->setArgument('--no-sandbox','');
          $HTML = view('downloadProfile')->render();
          $Chrome->useHTML($HTML);
          $Path = $Chrome->getPdf(public_path().'/'.Auth::user()->id.'/').PHP_EOL;
          return response()->download($Path, 'Resume.pdf')->deleteFileAfterSend(true);

It was in the documentation so I thought it was necessary, my apologies

Still timing out even after removing the PHP_EOL

can you try with simplest html as i mentioned above

$Chrome = new Chrome(NULL, '/usr/bin/google-chrome');

$Chrome->setWindowSize($width=1024, $height=768);

$Chrome->setArgument('--no-sandbox','');

$HTML = '<html>hey</html>';

$Chrome->useHTML($HTML);

$Path = $Chrome->getPdf(public_path().'/'.Auth::user()->id.'/');

return response()->download($Path, 'Resume.pdf')->deleteFileAfterSend(true);

I did try that, it still timed out

if you don't see any error it might be memory issue but try this way,

remove deleteFileAfterSend and verify manually if the file has been created there ? and also try to debug the path value ,

Still doesn't work for some unknown reason. If you wish I can give you the credentials to see if I effed up somewhere, but I followed instructions to the T

hey ,
did you run this example ?

$Chrome = new Chrome(NULL, '/usr/bin/google-chrome');

$Chrome->setWindowSize($width=1024, $height=768);

$Chrome->setArgument('--no-sandbox','');

$HTML = '<html>hey</html>';

$Chrome->useHTML($HTML);

$Path = $Chrome->getPdf(public_path().'/'.Auth::user()->id.'/Resume.pdf');

return response()->download($Path, 'Resume.pdf');

then check manually the resume in public path.
i think you were missing file name in getPdf method

$Chrome->getPdf(public_path().'/'.Auth::user()->id.'/Resume.pdf')

you had used this way

$Chrome->getPdf(public_path().'/'.Auth::user()->id.'/')

hope this would solve your problem , and sorry for late reply