File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 21
21
});
22
22
23
23
$ n = 0 ;
24
- $ loop ->addPeriodicTimer (2.0 , function () use ($ client , &$ n ) {
24
+ $ tid = $ loop ->addPeriodicTimer (2.0 , function () use ($ client , &$ n ) {
25
25
$ client ->send ('tick ' . ++$ n );
26
26
});
27
27
28
28
// read input from STDIN and forward everything to server
29
- $ loop ->addReadStream (STDIN , function () use ($ client ) {
30
- $ client ->send (trim (fgets (STDIN , 2000 )));
29
+ $ loop ->addReadStream (STDIN , function () use ($ client , $ loop , $ tid ) {
30
+ $ msg = fgets (STDIN , 2000 );
31
+ if ($ msg === false ) {
32
+ // EOF => flush client and stop perodic sending and waiting for input
33
+ $ client ->end ();
34
+ $ loop ->cancelTimer ($ tid );
35
+ $ loop ->removeReadStream (STDIN );
36
+ } else {
37
+ $ client ->send (trim ($ msg ));
38
+ }
31
39
});
32
40
}, function ($ error ) {
33
41
echo 'ERROR: ' . $ error ->getMessage () . PHP_EOL ;
You can’t perform that action at this time.
0 commit comments