Skip to content

Commit 93d433d

Browse files
committed
Merge branch 'master' into v1.6-master
2 parents e3225db + 8ff2904 commit 93d433d

12 files changed

+207
-22
lines changed

.github/workflows/acceptance.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Acceptance
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test-7-3:
7+
runs-on: ubuntu-latest
8+
name: Test PHP 7.3
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
- name: Set up PHP 7.3
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: '7.3'
16+
- name: Composer
17+
run: make install
18+
- name: Test
19+
run: make test
20+
21+
test-7-4:
22+
runs-on: ubuntu-latest
23+
name: Test PHP 7.4
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v2
27+
- name: Set up PHP 7.4
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: '7.4'
31+
- name: Composer
32+
run: make install
33+
- name: Test
34+
run: make test
35+
36+
test-8-0:
37+
runs-on: ubuntu-latest
38+
name: Test PHP 8.0
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v2
42+
- name: Set up PHP 8.0
43+
uses: shivammathur/setup-php@v2
44+
with:
45+
php-version: '8.0'
46+
- name: Composer
47+
run: make install
48+
- name: Test
49+
run: make test
50+
51+
test-8-1:
52+
runs-on: ubuntu-latest
53+
name: Test PHP 8.1
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v2
57+
- name: Set up PHP 8.1
58+
uses: shivammathur/setup-php@v2
59+
with:
60+
php-version: '8.1'
61+
- name: Composer
62+
run: make install
63+
- name: Test
64+
run: make test
65+
66+
cs-check:
67+
runs-on: ubuntu-latest
68+
name: Code standard
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@v2
72+
- name: Set up PHP 8.0
73+
uses: shivammathur/setup-php@v2
74+
with:
75+
php-version: '8.0'
76+
- name: Composer
77+
run: make install
78+
- name: Code standard
79+
run: make cs-check
80+
81+
coverage:
82+
runs-on: ubuntu-latest
83+
name: Code coverage
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v2
87+
- name: Set up PHP 8.0
88+
uses: shivammathur/setup-php@v2
89+
with:
90+
php-version: '8.0'
91+
extensions: xdebug
92+
- name: Composer
93+
run: make install
94+
- name: Code coverage
95+
env:
96+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
run: make coverage

.travis.yml

-14
This file was deleted.

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Websocket Client and Server for PHP
22

3-
[![Build Status](https://travis-ci.com/Textalk/websocket-php.svg?branch=master)](https://travis-ci.com/Textalk/websocket-php)
3+
[![Build Status](https://github.com/Textalk/websocket-php/actions/workflows/acceptance.yml/badge.svg)](https://github.com/Textalk/websocket-php/actions)
44
[![Coverage Status](https://coveralls.io/repos/github/Textalk/websocket-php/badge.svg?branch=master)](https://coveralls.io/github/Textalk/websocket-php)
55

66
This library contains WebSocket client and server for PHP.
@@ -62,4 +62,5 @@ $server->listen(function ($message, $connection = null) {
6262
Fredrik Liljegren, Armen Baghumian Sankbarani, Ruslan Bekenev,
6363
Joshua Thijssen, Simon Lipp, Quentin Bellus, Patrick McCarren, swmcdonnell,
6464
Ignas Bernotas, Mark Herhold, Andreas Palm, Sören Jensen, pmaasz, Alexey Stavrov,
65-
Michael Slezak, Pierre Seznec, rmeisler, Nickolay V. Shmyrev, Christoph Kempen.
65+
Michael Slezak, Pierre Seznec, rmeisler, Nickolay V. Shmyrev, Christoph Kempen,
66+
Marc Roberts.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require": {
2626
"php": "^7.2 | ^8.0",
27-
"psr/log": "^1.0"
27+
"psr/log": "^1 | ^2 | ^3"
2828
},
2929
"require-dev": {
3030
"phpunit/phpunit": "^8.0|^9.0",

docs/Changelog.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## `v1.6`
66

7-
> PHP version `^7.2|^8.0`
7+
> PHP version `^7.3|^8.0`
88
99
### `1.6.0`
1010

@@ -16,6 +16,15 @@
1616

1717
> PHP version `^7.2|^8.0`
1818
19+
### `1.5.5`
20+
21+
* Support for psr/log v2 and v3 (@simPod)
22+
* GitHub Actions replaces Travis (@sirn-se)
23+
24+
### `1.5.4`
25+
26+
* Keep open connection on read timeout (@marcroberts)
27+
1928
### `1.5.3`
2029

2130
* Fix for persistent connection (@sirn-se)

docs/Client.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ $client = new WebSocket\Client("ws://echo.websocket.org/", [
124124
'origin' => 'localhost',
125125
],
126126
'logger' => $my_psr3_logger, // Attach a PSR3 compatible logger
127-
'return_obj' => true, // Return Message insatnce rather than just text
127+
'return_obj' => true, // Return Message instance rather than just text
128128
'timeout' => 60, // 1 minute time out
129129
]);
130130
```

docs/Server.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ $server = new WebSocket\Server([
124124
'filter' => ['text', 'binary', 'ping'], // Specify message types for receive() to return
125125
'logger' => $my_psr3_logger, // Attach a PSR3 compatible logger
126126
'port' => 9000, // Listening port
127-
'return_obj' => true, // Return Message insatnce rather than just text
127+
'return_obj' => true, // Return Message instance rather than just text
128128
'timeout' => 60, // 1 minute time out
129129
]);
130130
```

lib/Connection.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,14 @@ public function read(string $length): string
486486
$data = '';
487487
while (strlen($data) < $length) {
488488
$buffer = fread($this->stream, $length - strlen($data));
489+
if (!$buffer) {
490+
$meta = stream_get_meta_data($this->stream);
491+
if (!empty($meta['timed_out'])) {
492+
$message = 'Client read timeout';
493+
$this->logger->error($message, $meta);
494+
throw new TimeoutException($message, ConnectionException::TIMED_OUT, $meta);
495+
}
496+
}
489497
if ($buffer === false) {
490498
$read = strlen($data);
491499
$this->throwException("Broken frame, read {$read} of stated {$length} bytes.");
@@ -527,7 +535,6 @@ private function throwException(string $message, int $code = 0): void
527535
$meta = $this->getMeta();
528536
$this->disconnect();
529537
}
530-
$json_meta = json_encode($meta);
531538
if (!empty($meta['timed_out'])) {
532539
$this->logger->error($message, $meta);
533540
throw new TimeoutException($message, ConnectionException::TIMED_OUT, $meta);

tests/ClientTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,18 @@ public function testBrokenRead(): void
382382
$client->receive();
383383
}
384384

385+
public function testReadTimeout(): void
386+
{
387+
MockSocket::initialize('client.connect', $this);
388+
$client = new Client('ws://localhost:8000/my/mock/path');
389+
$client->send('Connect');
390+
MockSocket::initialize('receive-client-timeout', $this);
391+
$this->expectException('WebSocket\TimeoutException');
392+
$this->expectExceptionCode(1024);
393+
$this->expectExceptionMessage('Client read timeout');
394+
$client->receive();
395+
}
396+
385397
public function testEmptyRead(): void
386398
{
387399
MockSocket::initialize('client.connect', $this);

tests/scripts/receive-broken-read.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
"params": [],
1212
"return": false
1313
},
14+
{
15+
"function": "stream_get_meta_data",
16+
"params": [
17+
"@mock-stream"
18+
],
19+
"return": {
20+
"timed_out": false,
21+
"blocked": true,
22+
"eof": true,
23+
"stream_type": "tcp_socket\/ssl",
24+
"mode": "r+",
25+
"unread_bytes": 2,
26+
"seekable": false
27+
}
28+
},
1429
{
1530
"function": "get_resource_type",
1631
"params": [
@@ -40,4 +55,4 @@
4055
],
4156
"return":true
4257
}
43-
]
58+
]
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[
2+
{
3+
"function": "get_resource_type",
4+
"params": [
5+
"@mock-stream"
6+
],
7+
"return": "stream"
8+
},
9+
{
10+
"function": "fread",
11+
"params": [],
12+
"return": false
13+
},
14+
{
15+
"function": "stream_get_meta_data",
16+
"params": [
17+
"@mock-stream"
18+
],
19+
"return": {
20+
"timed_out": true,
21+
"blocked": true,
22+
"eof": false,
23+
"stream_type": "tcp_socket\/ssl",
24+
"mode": "r+",
25+
"unread_bytes": 0,
26+
"seekable": false
27+
}
28+
},
29+
{
30+
"function": "get_resource_type",
31+
"params": [
32+
"@mock-stream"
33+
],
34+
"return": "stream"
35+
},
36+
{
37+
"function": "fclose",
38+
"params": [
39+
"@mock-stream"
40+
],
41+
"return":true
42+
}
43+
]

tests/scripts/receive-empty-read.json

+15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
"params": [],
1212
"return": ""
1313
},
14+
{
15+
"function": "stream_get_meta_data",
16+
"params": [
17+
"@mock-stream"
18+
],
19+
"return": {
20+
"timed_out": false,
21+
"blocked": true,
22+
"eof": false,
23+
"stream_type": "tcp_socket\/ssl",
24+
"mode": "r+",
25+
"unread_bytes": 0,
26+
"seekable": false
27+
}
28+
},
1429
{
1530
"function": "get_resource_type",
1631
"params": [

0 commit comments

Comments
 (0)