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

[Feature]: Document how to increase timeout #147

Closed
tacman opened this issue Jan 14, 2025 · 5 comments
Closed

[Feature]: Document how to increase timeout #147

tacman opened this issue Jan 14, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@tacman
Copy link

tacman commented Jan 14, 2025

Description

I'm trying to upload a large file, and it keeps timing out. How do I increase the timeout? I'm running from the CLI, so it shouldn't be a PHP timeout, but rather the HttpClient.

date && ./c bunny:upload data/met-raw.zip -vv 
Tue Jan 14 06:47:30 PM EST 2025

                                                                                                                        
 [INFO] bunny:upload started                                                                                            
                                                                                                                        

                                                                                                                        
 [INFO] Uploading data/met-raw.zip to museado/datamet-raw.zip                                                           
                                                                                                                        

23:47:31 INFO      [http_client] Request: "PUT https://ny.storage.bunnycdn.com/museado/data//met-raw.zip"
	
In Psr18Client.php line 118:
                                                                                         
  [Symfony\Component\HttpClient\Psr18NetworkException]                                   
  Idle timeout reached for "https://ny.storage.bunnycdn.com/museado/data//met-raw.zip".  
                                                                                         

Exception trace:
  at /home/tac/sites/mus/vendor/symfony/http-client/Psr18Client.php:118
 Symfony\Component\HttpClient\Psr18Client->sendRequest() at /home/tac/sites/mus/vendor/toshy/bunnynet-php/src/Client/BunnyClient.php:106
 ToshY\BunnyNet\Client\BunnyClient->request() at /home/tac/sites/mus/vendor/toshy/bunnynet-php/src/EdgeStorageAPI.php:104
 ToshY\BunnyNet\EdgeStorageAPI->uploadFile() at /home/tac/sites/survos/packages/bunny-bundle/src/Service/BunnyService.php:96
 Survos\BunnyBundle\Service\BunnyService->uploadFile() at /home/tac/sites/survos/packages/bunny-bundle/src/Command/BunnyUploadCommand.php:105
 Survos\BunnyBundle\Command\BunnyUploadCommand->__invoke() at n/a:n/a
 ReflectionFunction->invoke() at /home/tac/sites/mus/vendor/zenstruck/callback/src/Callback.php:90
 Zenstruck\Callback->invoke() at /home/tac/sites/mus/vendor/zenstruck/console-extra/src/Invokable.php:104
 Zenstruck\Console\InvokableCommand->execute() at /home/tac/sites/mus/vendor/zenstruck/console-extra/src/InvokableServiceCommand.php:106
 Zenstruck\Console\InvokableServiceCommand->execute() at /home/tac/sites/mus/vendor/symfony/console/Command/Command.php:279
 Symfony\Component\Console\Command\Command->run() at /home/tac/sites/mus/vendor/symfony/console/Application.php:1094
 Symfony\Component\Console\Application->doRunCommand() at /home/tac/sites/mus/vendor/symfony/framework-bundle/Console/Application.php:123
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /home/tac/sites/mus/vendor/symfony/console/Application.php:342
 Symfony\Component\Console\Application->doRun() at /home/tac/sites/mus/vendor/symfony/framework-bundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/tac/sites/mus/vendor/symfony/console/Application.php:193
 Symfony\Component\Console\Application->run() at /home/tac/sites/mus/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49
 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /home/tac/sites/mus/vendor/autoload_runtime.php:29
 require_once() at /home/tac/sites/mus/c:11

Example

No response

@tacman tacman added the enhancement New feature or request label Jan 14, 2025
@ToshY
Copy link
Owner

ToshY commented Jan 15, 2025

Hey @tacman 👋

Looking at the stack trace, you're using Symfony's Psr18Client. Have you tried setting the timeout/max_duration to see if that helps? If you've passed a (default) HttpClient / HttpClientInterface to it, then it should use the default values, which for timeout is ini_get('default_socket_timeout') and for max_duration this is set to 0, as can been seen from HttpClientInterface.

So you can try to set the timeout / max_duration for your default HTTP client in your config.

framework:
  http_client:
    default_options:
      retry_failed: true
      timeout: 180
      max_duration: 300

Or set it for the just the specific HTTP client:

$client = new Psr18Client(
    client: HttpClient::create(defaultOptions: [
        'timeout' => 180,
        'max_duration' => 300,
    ]),
);

Or you could try withOptions() on the PSR18 client (but I'm not entirely sure if max_duration would work for this)

Tip

Bonus: you can also nest the clients before construction the Psr18Client to make it more robust. As an example, you can use RetryableHttpClient with specific GenericRetryStrategy:

$client = new Psr18Client(
    new RetryableHttpClient(
        client: HttpClient::create(defaultOptions: [
            'timeout' => 180,
            'max_duration' => 300,
        ]),
        strategy: new GenericRetryStrategy(
            delayMs: 3000,
            multiplier: 5,
            jitter: 0.25,
        ),
    ),
);

I might consider updating the docs with example for EdgeStorageAPI::uploadFile / StreamAPI::uploadVideo (as this was asked in #46 before), but the point of implementing the PSR18 standard in this library is that it's now decoupled from a specific HTTP client implementation. Meaning that questions related to a specific HTTP client or its configuration (Symfony, Guzzle, etc.) don't really belong here.

If you however still think this is an issue regarding the library and/or its current implementation, then I'm more than happy to further debug the issue. To do this I would however need a reproducable example, with atleast the options to construct the Psr18Client and roughly how big your payload is.

@tacman
Copy link
Author

tacman commented Jan 15, 2025

Thanks! I don't think it's an issue of debugging, but rather as you've said, setting the client config which is specific to the client implementation.

Alas, I find that part confusing, I like Symfony Contracts because I'm a bit more familiar with them. But your examples are likely what I need, I'll give them a try. Thanks.

@tacman
Copy link
Author

tacman commented Jan 15, 2025

Indeed, that worked, thanks!

Although it is client-specific, adding this to the documentation would likely be helpful to others too.

@ToshY
Copy link
Owner

ToshY commented Jan 15, 2025

Indeed, that worked, thanks!

Great to hear.

Although it is client-specific, adding this to the documentation would likely be helpful to others too.

Could you clarify which options you've used and what values (and possibly the payload size for reference)? I'm normally all for updating the docs, so I will look for a place to put and format this properly then.

@ToshY
Copy link
Owner

ToshY commented Jan 22, 2025

After some consideration I still stand with my original point of view: the HTTP client specific options do not need to be documented here. The Symfony specific HTTP client options on how to change the timeout / max_timeout is given in an example mentioned before, so I'll leave it at that.

Closed as not planned.

@ToshY ToshY closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants