Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Doesnt work with PHP7 and ExtEventLoop #9

Closed
reflexator opened this issue Jun 6, 2016 · 9 comments
Closed

Doesnt work with PHP7 and ExtEventLoop #9

reflexator opened this issue Jun 6, 2016 · 9 comments

Comments

@reflexator
Copy link

reflexator commented Jun 6, 2016

Hi,

I have php 7 installed and I tried only working extension "event.so" for ReactPHP on PHP 7, but it doesnt work at all, it just make php to take 99% cpu power and 'freeze'

Testing code

<?php
require __DIR__.'/../vendor/autoload.php';


$loop = \React\EventLoop\Factory::create();
$handler = new \WyriHaximus\React\GuzzlePsr7\HttpClientAdapter($loop);

$client = new \GuzzleHttp\Client([
    'base_uri' => 'http://127.0.0.1/fake_web/',
    'handler' => \GuzzleHttp\HandlerStack::create($handler),
]);

$response = $client->get('http://127.0.0.1/fake_web/'); # ! this is row that stops script !
$html = (string) $response->getBody();

When I try same code with StreamSelectLoop it works

@WyriHaximus
Copy link
Owner

Hey thanks for reporting.

That is odd, does it output any errors? Can you give this code a try?:

<?php
require __DIR__.'/../vendor/autoload.php';


$loop = \React\EventLoop\Factory::create();
$handler = new \WyriHaximus\React\GuzzlePsr7\HttpClientAdapter($loop);

$client = new \GuzzleHttp\Client([
    'base_uri' => 'http://127.0.0.1/fake_web/',
    'handler' => \GuzzleHttp\HandlerStack::create($handler),
]);

$client->getAsync('http://127.0.0.1/fake_web/')->then(function ($response) {
    $html = (string) $response->getBody();
});

$loop->run();

@reflexator
Copy link
Author

reflexator commented Jun 8, 2016

Same result.

I tried to debug it, and it looks like this while is runned 4 times than freeze on @$this->eventBase->loop($flags);

React\EventLoop\ExtEventLoop.php

    /**
     * {@inheritdoc}
     */
    public function run()
    {
        $this->running = true;
        while ($this->running) {
            $this->nextTickQueue->tick();
            $this->futureTickQueue->tick();
            $flags = EventBase::LOOP_ONCE;
            if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) {
                $flags |= EventBase::LOOP_NONBLOCK;
            } elseif (!$this->streamEvents && !$this->timerEvents->count()) {
                break;
            }
            // @-suppression: https://github.com/reactphp/react/pull/234#discussion-diff-7759616R226
            @$this->eventBase->loop($flags);
        }
    }

When I removed @ to get some error messages, but didnt help

When I used reactPHP periodicalTimer ($loop->addPeriodicTimer) then loop normally works, but if i tried call Guzzle with React it just free as i mention.

@WyriHaximus
Copy link
Owner

What error messages did you get when removing the @? Will install ExtEventLoop on PHP7 when I get home tonight and have a go at it as well.

@reflexator
Copy link
Author

reflexator commented Jun 9, 2016

No error printed. It just run 3 times while loop in run function in ExtEventLoop.php and then halted on @$this->eventBase->loop($flags);

@WyriHaximus
Copy link
Owner

Alright installing the extension on php 7 isn't going according to my planning. Will try php 5 now first and venture back into php 7 tomorrow. The issue might also affect php 5. (My box is dual php 5 and 7.)

@WyriHaximus
Copy link
Owner

Managed to get an environment working to debug this issue in. Can reproduce the issue and conform that the event loop seems to work fine. The main issue I'm running into is that it can't seem to confirm a working stream. Currently debugging that issues. The interesting thing is that looking up DNS records works but something fails when doing the HTTP connection.

@WyriHaximus
Copy link
Owner

It's been over a year so assuming this isn't an issue any more, if it is please re-open and I'll have a loot at it again.

@markspare
Copy link

I think I may be experiencing this same issue.
I am using PHP7 and ExtEventLoop and if I attempt to call $client->request('GET', ......) client being a GuzzleHttp client with HttpClientAdapter I enter the promise wait function https://github.com/WyriHaximus/react-guzzle-psr7/blob/master/src/HttpClientAdapter.php#L149 which throws the following PHP Notice: EventBase::loop(): event_base_loop: reentrant invocation. Only one event_base_loop can run on each event_base at once. in /vendor/react/event-loop/src/ExtEventLoop.php on line 189.

I'm using this in conjuction with cboden/ratchet which I think may have something to do with it as if I do the same not in my Ratchet application the error doesn't occur

@WyriHaximus
Copy link
Owner

@markspare have you updated to the latest version? It contains some hacks to work around that specific hack.

P.S. Alternatively I would recommend using https://github.com/clue/reactphp-buzz if you run

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

No branches or pull requests

3 participants