Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
Fixes #68 : Added a sleep time after a message is sent
Browse files Browse the repository at this point in the history
  • Loading branch information
Taluu committed Sep 8, 2014
1 parent e61dbb5 commit 61f7eb8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Engine/AbstractSocketIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ protected function getDefaultOptions()
{
return ['context' => [],
'debug' => false,
'wait' => 100*1000,
'timeout' => ini_get("default_socket_timeout")];
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Engine/SocketIO/Version0X.php
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
9 changes: 7 additions & 2 deletions src/Engine/SocketIO/Version1X.php
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand All @@ -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} */
Expand Down

0 comments on commit 61f7eb8

Please sign in to comment.