Kucoin / kucoin-php-sdk

PHP SDK for KuCoin API.
https://docs.kucoin.com
MIT License
79 stars 41 forks source link

PHP Fatal error: Uncaught RuntimeException: Unable to set stream resource to non-blocking mode #68

Closed merovinh closed 3 months ago

merovinh commented 5 years ago

Hi guys! When I try to use WebSocket feed in coroutine, I get an error:

PHP Fatal error: Uncaught RuntimeException: Unable to set stream resource to non-blocking mode in .../vendor/react/stream/src/WritableResourceStream.php:35

<?php
include_once 'vendor/autoload.php';
use KuCoin\SDK\Auth;
use KuCoin\SDK\PrivateApi\WebSocketFeed;
use Ratchet\Client\WebSocket;
use React\EventLoop\LoopInterface;

Swoole\Runtime::enableCoroutine();

$api = new WebSocketFeed(null);

$query = ['connectId' => uniqid('', true)];

$channels = [
    ['topic' => '/market/ticker:ETH-BTC'],
];

go(function() use ($api, $query, $channels) {
    $api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) {
        var_dump($message);
        $loop->stop();
    }, function ($code, $reason) {});
});

My OS: Centos 7 PHP 7.1.16

userbig commented 4 years ago

For anyone who wonders how to fix this. You need to pas s SWOOLE_HOOK_SLEEP or SWOOLE_HOOK_CURL into Swoole\Runtime::enableCoroutine(); https://github.com/swoole/swoole-src/issues/2969

Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_SLEEP);

I have the same problem with running reactphp inside swoole coroutine;

1bazinga25 commented 4 years ago

Does this issue be solved now?

ISAAC-XXYYZZ commented 3 months ago

Since this issue has already been addressed and there have been no updates for a long time, we will now close it. If you need any further assistance, feel free to ask!