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

exceeded the timeout of 60 seconds ? #9

Closed
joruzani opened this issue Jun 12, 2014 · 38 comments
Closed

exceeded the timeout of 60 seconds ? #9

joruzani opened this issue Jun 12, 2014 · 38 comments

Comments

@joruzani
Copy link

Hi, I'm having a hard time making this work and don't know what to check.

Symfony \ Component \ Process \ Exception \ ProcessTimedOutException The process "/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy539a1b5171a923.27143750.html' '/tmp/knp_snappy539a1b5171b010.24930374.pdf'" exceeded the timeout of 60 seconds.

Thats been thrown.

Any ideas?
I already check that the bin is working

Thanks for any help =)

@joruzani joruzani changed the title Hi, I'm having a little problem making this work... I'm getting: Symfony \ Component \ Process \ Exception \ ProcessTimedOutException The process "/usr/local/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy539a1b5171a923.27143750.html' '/tmp/knp_snappy539a1b5171b010.24930374.pdf'" exceeded the timeout of 60 seconds. exceeded the timeout of 60 seconds ? Jun 12, 2014
@joruzani
Copy link
Author

those tmp files are created... which are the incomplete html and pdf (all the elements just with some css missing) and remain in the directory

@barryvdh
Copy link
Owner

Is this with all views? Can you try with a simple view with just plain text?
When you output the html of the view directly, does it all work?

@joruzani
Copy link
Author

Thanks for your response.

I haven't tried with any other view (will do), and the one I'm trying is really simple, just a list of items so just a table with text (it had images but I removed all for the moment).

The view loads well as if I dd($pdf) the object is created and the view displayed correctly(the ["html"] => string()).

I changed the timeout in the snappy AbstractGenerator.php so it may have more time to finish, I try with 360 and got the same result... I just set it to 0 (so timeout is disabled) and will let it run for a while to see what happens.

Edit: With no timeout is the browser the one that throws connection has timed out =(

Edit 2: without images it throws (in just 1 sec):

RuntimeException

The exit status code '1' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [======> ] 10% [=======> ] 12% [============================================================] 100% Counting pages (2/6) [============================================================] Object 1 of 1 Resolving links (4/6) [============================================================] Object 1 of 1 Loading headers and footers (5/6) Printing pages (6/6) [> ] Preparing [============================================================] Page 1 of 1 Done Exit with code 1 due to http error: 1302 " stdout: "" command:/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 '/tmp/knp_snappy539b125e497e95.90154509.html' '/tmp/knp_snappy539b125e4990c3.19775282.pdf'.

this is a snappy error so will check it and see what I find.

@joruzani
Copy link
Author

I've made various test, turns out the problem is (as expected) in the snappy and/or wkhtmltopdf... so I don't know if a should keep posting here.

Anyway here is what I found:

this will work:
$snappy->generate('http://www.google.com', '/tmp/testPdf.pdf');

this will work pretty well but maybe not perfectly
$snappy->generate('http://www.w3schools.com', '/tmp/testPdf.pdf');

throws (still generating the file):

RuntimeException

The exit status code '1' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [======> ] 10% QSslSocket: cannot resolve SSLv2_client_method QSslSocket: cannot resolve SSLv2_server_method [========> ] 14% [=========> ] 16% [===========> ] 19% [============> ] 21% [==============> ] 24% [===================> ] 33% [=========================> ] 43% [================================> ] 54% [========================================> ] 68% [============================================================] 100% [======> ] 10% [============================================================] 100% [======> ] 10% [============================================================] 100% [======> ] 10% [======> ] 10% [==================> ] 30% [==============================> ] 50% [==========================================> ] 70% [============================================================] 100% Counting pages (2/6) [============================================================] Object 1 of 1 Resolving links (4/6) [============================================================] Object 1 of 1 Loading headers and footers (5/6) Printing pages (6/6) [> ] Preparing [==============================> ] Page 1 of 2 [============================================================] Page 2 of 2 Done Exit with code 1 due to http error: 1005 " stdout: "" command: /vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 'http://www.w3schools.com' '/tmp/testPdf.pdf'.

and locally as in:
$snappy->generate('http://localhost:8000/items/9', '/tmp/testPdf.pdf');

throws (still generating the file):

ProcessTimedOutException

The process "/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 'http://localhost:8000/subastas/9' '/tmp/testPdf.pdf'" exceeded the timeout of 120 seconds.

I'll keep trying as I need this, but as the problem is not with your wrapper I won't post anymore unless you have no problem with that. If I found a solution I'll definitely post it =)

@joruzani
Copy link
Author

Ok, the solution is really simple actually, the problem is that it wont work on dev(local) environment because for some reason the wkhtmltopdf doesn't like localhost:8000... whatever. (I guess it has to be with how wk handless the address... maybe?)

and for example for the css the href needs to be complete (with http://):

this works -> http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css
this wont -> netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css

same with images or any other reference you may have.

That was all, sorry for any inconvenience =)

@mininoz
Copy link

mininoz commented Aug 28, 2014

I got the same error.

Symfony \ Component \ Process \ Exception \ ProcessTimedOutException
The process "/media/d_drive/vagrant/trusty64/www/travel/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality '/tmp/knp_snappy53ff3daf740c62.72948544.html' '/tmp/knp_snappy53ff3daf741394.68202889.pdf'" exceeded the timeout of 60 seconds.

whenever I try to call a css file in header, I will get the error.
{{ HTML::style('css/bootstrap.min.css') }}
or
<link rel="stylesheet" href="http://localhost:8000/css/bootstrap.min.css">

I will not get the error if I remove it or replace it with full url path
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

So the problem is I can not use my own css and put it into my template.

I ran on local by using built-in php server on ubuntu 14.04 (64 bit)
php artisan serve

anyway both file was create in tmp
/tmp/knp_snappy53ff3daf740c62.72948544.html
/tmp/knp_snappy53ff3daf741394.68202889.pdf -> I opened this file and it looked fine.

anyone got any solution for this?

Thank you

@barryvdh
Copy link
Owner

barryvdh commented Oct 7, 2014

Okay now facing the same issue after updating something (not sure what). The commands executes fine and the file is generated, but somehow not received correctly.

Related: KnpLabs/snappy#58

@saturday
Copy link

saturday commented Dec 3, 2014

I also encountered this issue, but in my case the timeout was due to a HostNotFoundError. Just remember if you add input rules to iptables and its policy is "drop", and you limit to a select few IP addresses, make sure you allow localhost access to itself. This is what caused the issue for me - also the process doesn't terminate, but that's a whole other issue.

Edit: I forgot to mention that this is marginally related to the inability to add relative urls.

@webdevilopers
Copy link

I just stumbled upon the same problem when adding an image from my own host which indeed is localhost:8000:

Any solution - workaround for this? Is it a wkhtmltopdf issue? Port problem?

@colejarczyk
Copy link

Try localhost with default HTTP port (80). Be sure that this image is available from machine where wkhtmltopdf tool is installed. Try download this image using wget.

@webdevilopers
Copy link

Thanks @colejarczyk . I couldn't switch the port to 80 due to permissions on my machine. But I switched to 8080.

A wget wget http://localhost:8080/logo.jpg would just work fine.

But I still have the same problem.

The strange thing is the wget http://localhost:8000/logo.jpg would take some time but work too.

@colejarczyk
Copy link

Try to execute render command in console. To get command you can "echo" it by call "getCommand" method of AbstractGenerator class. You should get more verbose output about problems.

@webdevilopers
Copy link

Good tip, thanks @colejarczyk . 👍 I will be able to check the project again next year. I will report then!

@webdevilopers
Copy link

Still checking the port problem. Testing the command next @colejarczyk .

Feel free to follow my steps on my gist:
https://gist.github.com/webdevilopers/e0d34a1c04ef2050a450

@webdevilopers
Copy link

I tried to get the command:

            $html = $this->renderView('AppBundle:Bundle:list.html.twig', $viewParameters);

            $snappy = $this->get('knp_snappy.pdf');

            echo $snappy->getInternalGenerator()->getCommand($html, 'test.pdf', array(
                    'orientation' => 'Landscape',
                    'images' => true,
                    'enable-javascript' => true
                ));

The result is a simple

wkhtmltopdf --lowquality --orientation 'Landscape' --images --enable-javascript ' 

I think the command is incomplete since it uses a symfony2 twig rendered template as $input, @colejarczyk?

@webdevilopers
Copy link

I found the root of my problems caused by the PHP built-in server because it is single-threaded, @colejarczyk .

Fur further details:
https://gist.github.com/webdevilopers/e0d34a1c04ef2050a450#comment-1368355

Thanks anyway!

@colejarczyk
Copy link

I would never thought that you'll trying to test wkhtmltopdf in PHP built-in server :)
To get full command, edit Abstract Generator class and echo command from method execute.
Use Vagrant as environment for testing.

@webdevilopers
Copy link

Believe me @colejarczyk , it was not my choice! ;) And yes, Vagrant is next! :)

@Wayne-Wen
Copy link

I meet the same timeout problem in our production server. It is weird that most of time, everything works fine and we can generate the PDF. I am using {{ HTML::style('my.css') }} or {{ HTML::script('my.js') }} for all css and js file. Does anyone know how to fix this problem?

@kenng
Copy link

kenng commented Sep 29, 2015

I have the same problem and was only realized it was due to the unstable version of wkhtmltopdf (0.11rc1). Wkhtmltopdf was hang and not returned, eventually causing the timeout. Switching to 0.12.1 fixed the problem.

@akshaykhale1992
Copy link

I have the same problem but in my case temp html files aren't being created and It works fine for few views but for one view its giving me problem
The view causing problem is reading data from a rest api and contains few images.
when I print the view content it's proper but when I try to create PDF its giving me timeout error.
Please help me.
Thanks in advance!

@fatihict
Copy link

I also run the PHP built in server and get a timeout-error if i try to access external css/js files. If i inline everything then it works like a charm.

@webdevilopers
Copy link

Did you check my comment @fatihict ?
#9 (comment)

@fatihict
Copy link

@webdevilopers Yes, i saw you comment. Thanks for your help.

@rvanlaak
Copy link

rvanlaak commented Mar 7, 2016

We also have the timeout, but it is expected because the html result is huge so it does really take Snappy over 60 seconds to generate the PDF. All issues I've found are related to wkhtmltopdf is waiting for content, but none of them actually provide a solution to increase the timeout for the Process component.

Is there another option next to calling set_time_limit() before the PDF will be generated? Can't seem to get the actual Process itself, otherwise setting the limit would be easy.

Edit: actually found the answer for that, the AbstractGenerator has a editable timeout parameter for that:

$this->get('knp_snappy.pdf')->getInternalGenerator()->setTimeout(300);

@eveyrat
Copy link

eveyrat commented May 2, 2016

Thanks @rvanlaak.

@bgarrison25
Copy link

@rvanlaak if i set this in the AppServiceProvider will all calls to Snappy pdf now have this timeout?

@rvanlaak
Copy link

rvanlaak commented Sep 8, 2016

@bgarrison25 you've got a link to the class you mean? We don't use this laravel wrapper bridge but use the KnpSnappyBundle, but I can't find the file in that bundle or even in this bundle or snappy itself.

@Lednerb
Copy link

Lednerb commented Sep 15, 2016

@barryvdh
Maybe my issue #129 has the same solution as @rvanlaak #9 (comment) mentioned.

@CharlyPoppins
Copy link

On our dedicated the timeout issue was solved by disabling ipv6.

@syc-pad
Copy link

syc-pad commented Aug 21, 2017

I had similar issue.
I solved it by calling {{public_path('css/mycss.css')}} instead of URL::to() or asset()

@michaelvickersuk
Copy link

Specifying a timeout value in config/snappy.php stopped this error occurring in my project.

@Kaz-
Copy link

Kaz- commented Jan 29, 2019

I had similar issue.
I solved it by calling {{public_path('css/mycss.css')}} instead of URL::to() or asset()

It worked for me ! Anyone can explain this?

@Lednerb
Copy link

Lednerb commented Jan 29, 2019

I had similar issue.
I solved it by calling {{public_path('css/mycss.css')}} instead of URL::to() or asset()

It worked for me ! Anyone can explain this?

The wkhtmltopdf does not use the actual browser domain to resolve the files.
The wkhtmltopdf binary is on your machine and needs the real file path to the associated files like images and stylesheets.

With public_path() you get the full path string like /var/www/html/public/css/mycss.css instead of http://example.org/css/mycss.css.

I had the same issue before.

@eldinphp
Copy link

eldinphp commented Mar 15, 2019

If someone else has this problem, well I found this kind-of solution .. i also use ngrok to put my site on the internet

Delete every redirects you have in hosts file (in linux its etc/hosts) except for example

mysite.test 127.0.0.1

also edit httpd-vhosts.conf file and delete other vhosts you have.. then run command from terminal
./ngrok http mysite.test:80

It should work.

I tried to use php -s command but it didn't work.

I use lampp (xampp for linux)

@elvincali
Copy link

I had similar issue.
I solved it by calling {{public_path('css/mycss.css')}} instead of URL::to() or asset()

Thanks!!!!, This has worked for me.

@sushansht
Copy link

I have this issue too. Mine is because of image in pdf which was taken form asset. I remove the image it works.

@jagadeshanh
Copy link

I had the same issue, it was because of internet (slow or not working), I then switched to different network and works fine. Just in case anyone have the same problem :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests