Code Monkey home page Code Monkey logo

Comments (8)

m6w6 avatar m6w6 commented on June 6, 2024

Thank you for the report!

from ext-http.

m6w6 avatar m6w6 commented on June 6, 2024

Looks like I'll have to disable/forbid resetting/dequeuing in the debug callback.

from ext-http.

MaikWagner avatar MaikWagner commented on June 6, 2024

Unfortunately, the problem occurs even in a more complex case with the request termination outside the setDebug() method.

<?php
class HTTPTransferObserver implements SplObserver {

        public function update(SplSubject $client, http\Client\Request $request = null, stdclass $progress = null)
        {
                return;
        }

        public function cancelRequest(http\Client $client, http\Client\Request $request, int $type, string $data)
        {
                if ($type & http\Client::DEBUG_HEADER) {
                        $client->reset();
                }
        }
}

$c = new http\Client;

$c->enqueue($request = new http\Client\Request("GET", "https://m6w6.name"));

$observer = new HTTPTransferObserver($request);

$c->attach($observer);

$c->setDebug(function(http\Client $c, http\Client\Request $r, int $type, string $data) {
        foreach ($c->getObservers() as $observer) {
                $observer->cancelRequest($c, $r, $type, $data);
        }
});

$c->send();

from ext-http.

MaikWagner avatar MaikWagner commented on June 6, 2024

We tried to reconstruct the problem with an C code example of curl (curl/docs/examples/http2-download.c) whereby the issue didn't appear.

http2-download.c.zip

from ext-http.

m6w6 avatar m6w6 commented on June 6, 2024

Your first example is still resetting/dequeuing while the callback is running.

The second example doesn't do all the things that are done otherwise, like curl_multi_remove_handle etc.

The problem apparently is, that we invalidate the easy handle on reset/dequeue while libcurl is still operating on that handle when we return from the callback.

from ext-http.

MaikWagner avatar MaikWagner commented on June 6, 2024

It would be a pity to lose this feature, but perhaps you have another idea how we could solve the problem?

from ext-http.

m6w6 avatar m6w6 commented on June 6, 2024

@bagder just verified that it's probalby unsafe to call curl_multi_remove_handle from within the callback, so I tried to put something together, that would help you anyway:

$c = new http\Client;
$c->enqueue(new http\Client\Request("GET", "http://example.com"));

$c->setDebug(function($client, $request, $type, $data) use (&$dequeue) {
    if (!$type) {
        printf("D: %d <%s>\n", $type, $data);
        if (sscanf($data, "\tTrying %s...", $ip)) {
            printf("Blocking %s\n", $ip);
            $dequeue[] = $request;
        }
    }
});
while ($c->once()) {
    while ($dequeue) {
        $c->dequeue(array_shift($dequeue));
    }
    $c->wait();
}

HTH

from ext-http.

MaikWagner avatar MaikWagner commented on June 6, 2024

thx, that helps!

from ext-http.

Related Issues (20)

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.