From 61f7eb8dcc2ac939aad526745c8042ce1cd4a54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Mon, 8 Sep 2014 12:52:10 +0200 Subject: [PATCH] Fixes #68 : Added a sleep time after a message is sent --- src/Engine/AbstractSocketIO.php | 1 + src/Engine/SocketIO/Version0X.php | 7 ++++++- src/Engine/SocketIO/Version1X.php | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Engine/AbstractSocketIO.php b/src/Engine/AbstractSocketIO.php index 33722c8..b30745d 100644 --- a/src/Engine/AbstractSocketIO.php +++ b/src/Engine/AbstractSocketIO.php @@ -200,6 +200,7 @@ protected function getDefaultOptions() { return ['context' => [], 'debug' => false, + 'wait' => 100*1000, 'timeout' => ini_get("default_socket_timeout")]; } } diff --git a/src/Engine/SocketIO/Version0X.php b/src/Engine/SocketIO/Version0X.php index f9fd197..476c88e 100644 --- a/src/Engine/SocketIO/Version0X.php +++ b/src/Engine/SocketIO/Version0X.php @@ -105,7 +105,12 @@ public function write($code, $message = null) } $payload = new Encoder($code . ':::' . $message, Encoder::OPCODE_TEXT, true); - return fwrite($this->stream, (string) $payload); + $bytes = fwrite($this->stream, (string) $payload); + + // wait a little bit of time after this message was sent + usleep($this->options['wait']); + + return $bytes; } /** {@inheritDoc} */ diff --git a/src/Engine/SocketIO/Version1X.php b/src/Engine/SocketIO/Version1X.php index 778271c..9239724 100644 --- a/src/Engine/SocketIO/Version1X.php +++ b/src/Engine/SocketIO/Version1X.php @@ -81,7 +81,7 @@ public function close() /** {@inheritDoc} */ public function emit($event, array $args) { - $this->write(EngineInterface::MESSAGE, static::EVENT . json_encode([$event, $args])); + return $this->write(EngineInterface::MESSAGE, static::EVENT . json_encode([$event, $args])); } /** {@inheritDoc} */ @@ -96,7 +96,12 @@ public function write($code, $message = null) } $payload = new Encoder($code . $message, Encoder::OPCODE_TEXT, true); - return fwrite($this->stream, (string) $payload); + $bytes = fwrite($this->stream, (string) $payload); + + // wait a little bit of time after this message was sent + usleep((int) $this->options['wait']); + + return $bytes; } /** {@inheritDoc} */