From aa071b84e68f217e71a7fae6514d6f63e7077e64 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 31 Aug 2014 08:28:17 -0400 Subject: [PATCH] Only do file_get_contents on PHP versions needed --- src/StreamEncryption.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/StreamEncryption.php b/src/StreamEncryption.php index 79c71b8..de0eba0 100644 --- a/src/StreamEncryption.php +++ b/src/StreamEncryption.php @@ -18,10 +18,23 @@ class StreamEncryption private $errstr; private $errno; + + private $wrapSecure = false; public function __construct(LoopInterface $loop) { $this->loop = $loop; + + // See https://bugs.php.net/bug.php?id=65137 + // On versions affected by this bug we need to fread the stream until we + // get an empty string back because the buffer indicator could be wrong + if ( + PHP_VERSION_ID < 50433 + || (PHP_VERSION_ID >= 50000 && PHP_VERSION_ID < 50517) + || PHP_VERSION_ID === 50600 + ) { + $this->wrapSecure = true; + } } public function enable(Stream $stream) @@ -59,7 +72,7 @@ public function toggle(Stream $stream, $toggle) $toggleCrypto(); return $deferred->promise()->then(function () use ($stream, $toggle) { - if ($toggle) { + if ($toggle && $this->wrapSecure) { return new SecureStream($stream, $this->loop); }