Giter Site home page Giter Site logo

Comments (15)

timopruesse avatar timopruesse commented on May 11, 2024

I need more information to answer that. It could be something simple (e.g. PHP version too old).
If you provide a code example and your PHP version, I might be able to pin it down.

from guzzle-advanced-throttle.

f-liva avatar f-liva commented on May 11, 2024
$options = [
	'base_uri' => 'https://api.entstix.com/api/v1/xlive/',
	'headers' => [
		'Accept-Language' => 'en',
	],
	'auth' => ['username', 'password'],
];

$stack = HandlerStack::create();
$client = GuzzleThrottle::client(array_merge($options, ['handler' => $stack]);

$response = $client->get('content/attraction');

echo $response->getBody()->getContents();

and the result is

image

but, changing

$client = GuzzleThrottle::client(array_merge($options, ['handler' => $stack]);

in

$client = new \GuzzleHttp\Client(array_merge($options, ['handler' => $stack]);

get everything works fine

from guzzle-advanced-throttle.

f-liva avatar f-liva commented on May 11, 2024

I'm running on laravel/homestead latest version

from guzzle-advanced-throttle.

timopruesse avatar timopruesse commented on May 11, 2024

Ah, so you are using the Laravel wrapper. There might be a problem with how you initialize the handler stack. Maybe you can try it with new HandlerStack() instead of HandlerStack::create() (I don't know if it makes a difference, though). Another thing to try first would be to see if it makes a difference to pass the array directly instead of using array_merge.

But I'll have a look this evening when I'm home. Shouldn't be that hard to find the issue :)

from guzzle-advanced-throttle.

f-liva avatar f-liva commented on May 11, 2024

Thank you

Yes I tried with the bridge and without, with array merge and without (no issue here) and with new HandlerStack or with HandlerStack::create (same issue)

The only thing get things work is use the standard Guzzle Client. Adding the throttle middlewere get things broke.

from guzzle-advanced-throttle.

timopruesse avatar timopruesse commented on May 11, 2024

It would be helpful if you could provide me the config you use for the middleware. Then it's easier to debug it later (the one you created with vendor:publish).

from guzzle-advanced-throttle.

f-liva avatar f-liva commented on May 11, 2024

Sure

<?php

// @codeCoverageIgnoreStart

// example configuration
return [
    'cache' => [
        // Name of the configured driver in the Laravel cache config file / Also needs to be set when "no-cache" is set! Because it's used for the internal timers
        'driver' => env('CACHE_DRIVER'),
        // Cache strategy: no-cache, cache, force-cache
        'strategy' => 'force-cache',
        // TTL in minutes
        'ttl' => 900,
    ],
    'rules' => [
        // host (including scheme)
        'https://api.getyourguide.com' => [
            [
                // maximum number of requests in the given interval
                'max_requests' => 600,
                // interval in seconds till the limit is reset
                'request_interval' => 60,
            ],
        ],
        /**
         * @see https://mail.mixmax.com/m/sjn5eJw7arzyEEW4Z
         */
        'https://prelive.viatorapi.viator.com' => [
            [
                'max_requests' => 15,
                'request_interval' => 10,
            ],
        ],
        /**
         * @see https://mail.mixmax.com/m/sjn5eJw7arzyEEW4Z
         */
        'https://viatorapi.viator.com' => [
            [
                'max_requests' => 45,
                'request_interval' => 10,
            ],
        ],
    ],
];

// @codeCoverageIgnoreEnd

the cache driver is redis, but same issue on file drive

from guzzle-advanced-throttle.

timopruesse avatar timopruesse commented on May 11, 2024

I think it is a problem with the authorization. If I use your exact configuration with another endpoint that doesn't require auth it works perfectly. I don't have permission to access https://api.entstix.com/api/v1/xlive/.

I can set up an environment that requires authentication tomorrow and check what the root cause is.

from guzzle-advanced-throttle.

f-liva avatar f-liva commented on May 11, 2024

Thank you

Let me know if you need that auth credentials

from guzzle-advanced-throttle.

timopruesse avatar timopruesse commented on May 11, 2024

I just had another look at it. I think the stream is at a wrong position and not rewinded correctly in that case.

Can you try to get the contents with echo (string) $response->getBody(); and report back what it returns?

from guzzle-advanced-throttle.

f-liva avatar f-liva commented on May 11, 2024

Yes, it works!

Why instead with the middle ...->getContents() got error?

from guzzle-advanced-throttle.

timopruesse avatar timopruesse commented on May 11, 2024

getBody will always return the whole response body, see https://guzzle3.readthedocs.io/http-client/response.html#response-body or in the new documentation here: http://docs.guzzlephp.org/en/stable/psr7.html?highlight=getbody#body

getContents returns the response body from the current position of the stream/file pointer.

I'll create a new issue for that later when I'm home. But I won't be able to fix that behavior before next week, sorry.

from guzzle-advanced-throttle.

f-liva avatar f-liva commented on May 11, 2024

Ouch, thanks for the explanation!

from guzzle-advanced-throttle.

timopruesse avatar timopruesse commented on May 11, 2024

Doesn't seem like an easy fix.
The logging middleware has similar problems (see guzzle/guzzle#1582).

Gonna close this for now.

from guzzle-advanced-throttle.

f-liva avatar f-liva commented on May 11, 2024

Okay

The casting anyway solved my problem

from guzzle-advanced-throttle.

Related Issues (8)

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.