|
5 | 5 | use Evenement\EventEmitter; |
6 | 6 | use React\EventLoop\LoopInterface; |
7 | 7 | use React\Stream\DuplexResourceStream; |
8 | | -use React\Stream\Stream; |
9 | 8 | use React\Stream\Util; |
10 | 9 | use React\Stream\WritableStreamInterface; |
| 10 | +use React\Stream\WritableResourceStream; |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * The actual connection implementation for ConnectionInterface |
@@ -50,20 +50,24 @@ public function __construct($resource, LoopInterface $loop) |
50 | 50 | // See https://bugs.php.net/bug.php?id=65137 |
51 | 51 | // https://bugs.php.net/bug.php?id=41631 |
52 | 52 | // https://github.com/reactphp/socket-client/issues/24 |
53 | | - $clearCompleteBuffer = (version_compare(PHP_VERSION, '5.6.8', '<')); |
54 | | - |
55 | | - // @codeCoverageIgnoreStart |
56 | | - if (class_exists('React\Stream\Stream')) { |
57 | | - // legacy react/stream < 0.7 requires additional buffer property |
58 | | - $this->input = new Stream($resource, $loop); |
59 | | - if ($clearCompleteBuffer) { |
60 | | - $this->input->bufferSize = null; |
61 | | - } |
62 | | - } else { |
63 | | - // preferred react/stream >= 0.7 accepts buffer parameter |
64 | | - $this->input = new DuplexResourceStream($resource, $loop, $clearCompleteBuffer ? -1 : null); |
65 | | - } |
66 | | - // @codeCoverageIgnoreEnd |
| 53 | + $clearCompleteBuffer = PHP_VERSION_ID < 50608; |
| 54 | + |
| 55 | + // PHP < 7.1.4 (and PHP < 7.0.18) suffers from a bug when writing big |
| 56 | + // chunks of data over TLS streams at once. |
| 57 | + // We try to work around this by limiting the write chunk size to 8192 |
| 58 | + // bytes for older PHP versions only. |
| 59 | + // This is only a work-around and has a noticable performance penalty on |
| 60 | + // affected versions. Please update your PHP version. |
| 61 | + // This applies to all streams because TLS may be enabled later on. |
| 62 | + // See https://github.com/reactphp/socket/issues/105 |
| 63 | + $limitWriteChunks = (PHP_VERSION_ID < 70018 || (PHP_VERSION_ID >= 70100 && PHP_VERSION_ID < 70104)); |
| 64 | + |
| 65 | + $this->input = new DuplexResourceStream( |
| 66 | + $resource, |
| 67 | + $loop, |
| 68 | + $clearCompleteBuffer ? -1 : null, |
| 69 | + new WritableResourceStream($resource, $loop, null, $limitWriteChunks ? 8192 : null) |
| 70 | + ); |
67 | 71 |
|
68 | 72 | $this->stream = $resource; |
69 | 73 |
|
|
0 commit comments