library/Rediska/PubSub/Channel.php
public function getMessage($timeout = null)
    {
        // Get default timeout
        if (!$timeout && $this->getTimeout()) {
            $timeout = $this->getTimeout();
        }

        // Start timer if not started from iterator
        if ($timeout && $this->_needStart) {
            $this->_timeStart = microtime(true);
        }

        // Get message from connections
        while (true) {
            // Try to get message from buffer
            if (!empty(self::$_messages)) {
                /* @var $connection Rediska_Connection */
                foreach($this->_connections as $connection) {
                    $channels = $this->_connections->getChannelsByConnection($connection);
                    foreach($channels as $channel) {
                        $key = "{$connection->getAlias()}-$channel";
                        if (isset(self::$_messages[$key])) {
                            $message = array_shift(self::$_messages[$key]);
                            if (empty(self::$_messages[$key])) {
                                unset(self::$_messages[$key]);
                            }
    
                            return $message;
                        }
                    }
                }
            }

            if (empty($this->_subscriptions)) {
                return null;
            }

            /* @var $connection Rediska_Connection */
            foreach ($this->_connections as $connection) {
                if ($timeout) {
                    $timeLeft = ($this->_timeStart + $timeout) - microtime(true);

                    if ($timeLeft <= 0) {
                        // Reset timeStart if time started from this method
                        if ($this->_needStart) {
                            $this->_timeStart = 0;
                        }

                        return null;
                    }

                    $connection->setReadTimeout($timeLeft);
                } else {
                    $connection->setReadTimeout(600);
                }

                try {
                    $response = $this->_getResponseFromConnection($connection);

                    if ($response === null) {
                        // Sleep before next connection check
                        usleep(10000); // 0.01 sec
                        continue;
                    }

                    if (!in_array($response->getChannel(), $this->_subscriptions)) {
                        $this->_addMessageToBuffer($response);
                        continue;
                    }

                    // Reset timeStart if time started from this method 
                    if ($this->_needStart) {
                        $this->_timeStart = 0;
                    }

                    return $response;
                } catch (Rediska_Connection_TimeoutException $e) {
                    if (!$timeout) {
                        continue;
                    }

                    // Reset timeStart if time started from this method
                    if ($this->_needStart) {
                        $this->_timeStart = 0;
                    }

                    return null;
                }
            }
        }
    }
public function getMessage($timeout = null)
    {
        // Get default timeout
        if (!$timeout && $this->getTimeout()) {
            $timeout = $this->getTimeout();
        }

        // Start timer if not started from iterator
        if ($timeout && $this->_needStart) {
            $this->_timeStart = microtime(true);
        }

        // Get message from connections
        while (true) {
            // Try to get message from buffer
            if (!empty(self::$_messages)) {
                /* @var $connection Rediska_Connection */
                foreach($this->_connections as $connection) {
                    $channels = $this->_connections->getChannelsByConnection($connection);
                    foreach($channels as $channel) {
                        $key = "{$connection->getAlias()}-$channel";
                        if (isset(self::$_messages[$key])) {
                            $message = array_shift(self::$_messages[$key]);
                            if (empty(self::$_messages[$key])) {
                                unset(self::$_messages[$key]);
                            }
    
                            return $message;
                        }
                    }
                }
            }

            if (empty($this->_subscriptions)) {
                return null;
            }

            /* @var $connection Rediska_Connection */
            foreach ($this->_connections as $connection) {
                if ($timeout) {
                    $timeLeft = ($this->_timeStart + $timeout) - microtime(true);

                    if ($timeLeft <= 0) {
                        // Reset timeStart if time started from this method
                        if ($this->_needStart) {
                            $this->_timeStart = 0;
                        }

                        return null;
                    }

                    $connection->setReadTimeout($timeLeft);
                } else {
                    $connection->setReadTimeout(600);
                }

                try {
                    $response = $this->_getResponseFromConnection($connection);

                    if ($response === null) {
                        // Sleep before next connection check
                        usleep(10000); // 0.01 sec
                        continue;
                    }

                    if (!in_array($response->getChannel(), $this->_subscriptions)) {
                        $this->_addMessageToBuffer($response);
                        continue;
                    }

                    // Reset timeStart if time started from this method 
                    if ($this->_needStart) {
                        $this->_timeStart = 0;
                    }

                    return $response;
                } catch (Rediska_Connection_TimeoutException $e) {
                    if (!$timeout) {
                        continue;
                    }

                    // Reset timeStart if time started from this method
                    if ($this->_needStart) {
                        $this->_timeStart = 0;
                    }

                    return null;
                }
            }
        }
    }
Get message

@param float[optional] Timeout The timeout in seconds. Since this is a float it allows sub-second accuracy (For example 0.2 for 200 msec)
@return Rediska_PubSub_Response_Message|null