-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Stream reads blocking with Stream::handleData's fread #17
Comments
FYI it looks like a similar issue was noted in reactphp/socket: https://github.com/reactphp/socket/blob/master/src/Connection.php#L11-L13 In my fork, I have changed the Edit: Looks like |
What operating system are you running this on? |
This is on CentOS. I have tested it on 6.5 and 6.6. |
First try taking your logger out. By default the STDOUT stream blocks. If your'e still having the issue next I'd suggest trying Pawl as your WebSocket client. |
I tried setting the logger to /dev/null instead of php://stdout, but I got the same result. Unfortunately phpws requires the logger. I'm pretty positive that it's not related to the logger.. the In any case, Pawl looks nice.. I may end up going that route. |
Okay, I tested this with Pawl as well, completely removing my code and the logger except for a required API call to get the websocket URL. It still lags behind by one message..
class TestCommand extends CConsoleCommand {
public function run($args){
$slack = Slack\Slack::factory();
$ws = $slack->startRtm();
$loop = \React\EventLoop\Factory::create();
$connector = new \Ratchet\Client\Factory($loop);
$connector($ws)->then(function(\Ratchet\Client\WebSocket $conn) use ($slack){
$slack->setClient($conn);
$conn->on("message", function($message){
echo "Got message: $message".PHP_EOL;
});
}, function ($e) use ($loop){
echo "Could not connect: {$e->getMessage()}";
$loop->stop();
});
$loop->run();
}
} As of the above, I had sent two messages: "test" and "test2". When using I hope that all makes sense. |
I took it even further and took Yii out of the loop as well. Just a bare test program using only Pawl and a url provided from argv.. <?php
require("protected/vendor/autoload.php");
$loop = \React\EventLoop\Factory::create();
$connector = new \Ratchet\Client\Factory($loop);
$connector($argv[1])->then(function(\Ratchet\Client\WebSocket $conn){
$conn->on("message", function($message){
echo "Got message: $message".PHP_EOL;
});
}, function ($e) use ($loop){
echo "Could not connect: {$e->getMessage()}";
$loop->stop();
});
$loop->run(); This, still, showed the same symptoms as phpws. If the |
What's the output of |
This is in a brand new folder - only Pawl in composer.json. |
Hmm, I was thinking it could have been an SSL bug we recently (thought) we fixed in socket-client...Can you try the same thing but without SSL by any chance? |
Unfortunately I can't get a ws:// for Slack.. they only give me wss :( I tested with ws(s)://echo.websocket.org and it seems to work OK.. I I don't know of anything else to test with; perhaps something more involved than an echo server. Do you have any ideas? |
For fun, I tested the Slack WSS URL with an external tester. I used the "Simple WebSocket Client" Chrome Extension, connected to the URL that Slack gave me, and did not observe this problem. There was no blocking, and messages came through A-OK. |
In your vendor folder find this file/line - change the code to force |
Yep, that fixed the problem.
Perhaps it's an issue with Remi's 5.5.20 build - or it affects this version too? |
According to the latest comment the fix @DaveRandom applied has been reverted due to a bug that blocks connecting. Until that's resolved (again) we'll have to remove that version check condition in SocketClient. I'll start work on that tonight after work. |
OK - thank you! I really appreciate the help. It's a shame they reverted it :( Would you like me to open up an issue on socket-client and reference/close this thread? |
Yes please! |
Done! Thanks again! |
Hello,
I ran into an interesting issue with this library when attempting to use Devristo/phpws and its builtin websocket client. When data is read from a stream using the Stream class' handleData function, reads seem to be blocking even though stream_set_blocking is called in __construct. I found that replacing line 121's
fread
with astream_get_contents
resolved my blocking reads issue. I feel like this class should be using thestream_
functions anyways - but it seems like a mix off*
andstream_
functions are used.Is there a possibility a fix for this can be issued?
The only way I know to reproduce this involves a lot of steps and a specific product (Slack) and protocol (Hybi Websockets). I have tested that this issue exists on multiple boxes using PHP 5.5. I'll outline the steps to reproduce..
rtm.start
call. This will give you a Websocket URL to connect to (must be used within 30 seconds, FYI). It's at the very bottom of the output. https://api.slack.com/methods/rtm.start/testAgain, I know this is kind of a weird example, but it's the only thing I've been using this lib for and I don't have another websocket service I can test. It may be related to how the websocket clients end their frames/lines and how fread expects them to end... I'm not completely sure.
Let me know if you need more information on this. I will be happy to provide what I can.
The text was updated successfully, but these errors were encountered: