gotenberg/gotenberg-php

Laravel Sail Internal URLs not working 8.2.0

Closed this issue · 4 comments

I'm having an issue on 8.2.0 (Maybe related to gotenberg/gotenberg#403?)

Using Laravel + Sail on WSL2

docker-compose.yml
    gotenberg:
        image: gotenberg/gotenberg:8
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${FORWARD_GOTENBERG_PORT:-3000}:3000'
        volumes:
            - './public/fonts:/usr/local/share/fonts'
        command:
            - "gotenberg"
            - "--log-level=debug"
        networks:
            - sail

ive made a static page at /sample which literally says just "Hello, World!"

from inside the gotenberg container curl http://laravel.test/sample works fine

I can run the following from inside the laravel app container (not the gotenberg container)

curl \
--request POST http://gotenberg:3000/forms/chromium/convert/url \
--form url=http://laravel.test/sample \
-o my.pdf

it works fine, my.pdf appears in the project root. with the words "Hello, World!" on it.

But from the application when I run (gotenberg/gotenberg-php)

$request = Gotenberg::chromium(config('gotenberg.url'))
                            ->pdf()
                            ->failOnConsoleExceptions()
                            ->outputFilename('my-custom-pdf')
                            ->url('http://laravel.test:80/sample');

        $response = Gotenberg::send($request);

        return $response
            ->withHeader('Content-Type', 'application/pdf')
            ->withHeader('Content-Disposition', 'inline; filename="generated.pdf"');

I keep getting:

ypa-filament-app-gotenberg-1  | {"level":"error","ts":1709274087.9005635,"logger":"api","msg":"convert URL to PDF: conv
ert to PDF: context deadline exceeded","trace":"efa04a81-fb5a-4cfe-abb3-80e0d6e81a00","remote_ip":"172.23.0.8","host":"
gotenberg:3000","uri":"/forms/chromium/convert/url","method":"POST","path":"/forms/chromium/convert/url","referer":"","
user_agent":"GuzzleHttp/7","status":503,"latency":30000270232,"latency_human":"30.000270232s","bytes_in":316,"bytes_out":19}

P.S. if i call ->html(Stream::string('sample', view('sample')->render())) though it does work. its only url() thats the problem. But if I have any images in the view the same timeout happens. The image urls also are something like 'http://localhost/img/example.jpg' and I don't think the Gotenberg container can resolve localhost so I'm not even sure what the correct implementation is.

Been fighting this all day. Please help 🙏

Hello @wazimshizm,

The URL method just set the url form field so I don’t understand why you’re encountering this issue.

Maybe try to remove the :80 from the URL?

Hello @wazimshizm,

The URL method just set the url form field so I don’t understand why you’re encountering this issue.

Maybe try to remove the :80 from the URL?

Even with :80 removed it makes no difference. I've tried so many variations.

No idea on what’s going on here 🤷‍♂️

You may try skipNetworkIdleEvent to improve the rendering time.

@gulien not your fault at all. It's so obvious now. 🤦‍♂️

For anyone else with this problem, it's because Laravel Sail only has one worker by default, which is occupied by the initial request. When gotenberg makes it's request back, it times out. This isn't a problem with queued processes obviously.

Add PHP_CLI_SERVER_WORKERS=2 to your .env file and restart sail.