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

[RFC] Add a way to make Redis::subscribe() async #1728

Open
lyrixx opened this issue Mar 20, 2020 · 0 comments
Open

[RFC] Add a way to make Redis::subscribe() async #1728

lyrixx opened this issue Mar 20, 2020 · 0 comments

Comments

@lyrixx
Copy link

@lyrixx lyrixx commented Mar 20, 2020

Expected behaviour

<?php

$redis = new \Redis();
$redis->connect('172.17.0.2');

function f() {
    dump(func_get_args());
}

dump("START");

$redis->subscribe(['test'], 'f');

// Be able to run some code...
dump('we continue');

This is does not work since Redis::subscribe() is blocking.
It would be nice to have the same system as pcntl_signal().

It would be even more awesome it this could work with signal:

<?php

$redis = new \Redis();
$redis->connect('172.17.0.2');

function f() {
    dump(func_get_args());
}

dump("START");

pcntl_async_signals(true);
$shouldStop = false;
pcntl_signal(SIGINT, function () use (&$shouldStop) {
    dump('CTRL+C detected!');
    $shouldStop = true;

    exit(1);
});

$redis->subscribe(['test'], 'f');

while (true) {
    echo ".";
    if ($shouldStop) {
        echo "\n";
        return;
    }
    sleep(1);
}

Actual behaviour

The following line blocks the script

$redis->subscribe(['test'], 'f');

I'm seeing this behaviour on

  • OS: ubuntu
  • Redis: 5+
  • PHP: 7.4+
  • phpredis: 5.2.0

I've checked

  • There is no similar issue from other users
  • Issue isn't fixed in develop branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.