I’m creating an IRC bot using PHP (not that that should matter) and I’ve ran into an issue where sending messages with a short time between them will result in only the latest message being sent. (i.e. if I write “PRIVMSG #channel Hello” and then “PRIVMSG #channel world” with less than a second delay between them, only “world” will appear in the chat)
I created a temporary workaround, which is a queue system that sends each message at least 1.25 seconds after the previous one. But why can’t I send sequential messages quickly? Is this normal? I would think not, since I’m able to send messages quickly one after the other on Twitch’s website, and using a test with two browsers showed little delay between sending and receiving.
I have socket blocking turned off and use stream_select (with $tv_sec set to 0 and $tv_usec set to 200000) to detect activity in the socket. I do this because I have some commands that will send a message, wait a few seconds and then send another one. If stream blocking were turned on, the second message would only be sent once someone chatted, which isn’t what I was looking for. I doubt this would cause or influence this problem, but you never know.
EDIT: Here’s a snippet of PHP code I use when establishing a connection.
$this->context = stream_context_create(array(‘socket’ => array(‘bindto’ => ‘0:0’)));
$addr = ‘tcp://’ . $this->server . ‘:’ . (string)$this->port;
if($this->socket = stream_socket_client($addr, $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $this->context)){
stream_set_blocking($this->socket, 0);
…Login, join, pass, nick, etc.
}