Credis_Client::write_command PHP Method

write_command() protected method

protected write_command ( $command )
    protected function write_command($command)
    {
        // Reconnect on lost connection (Redis server "timeout" exceeded since last command)
        if (feof($this->redis)) {
            $this->close();
            // If a watch or transaction was in progress and connection was lost, throw error rather than reconnect
            // since transaction/watch state will be lost.
            if ($this->isMulti && !$this->usePipeline || $this->isWatching) {
                $this->isMulti = $this->isWatching = FALSE;
                throw new CredisException('Lost connection to Redis server during watch or transaction.');
            }
            $this->connected = FALSE;
            $this->connect();
            if ($this->authPassword) {
                $this->auth($this->authPassword);
            }
            if ($this->selectedDb != 0) {
                $this->select($this->selectedDb);
            }
        }
        $commandLen = strlen($command);
        $lastFailed = FALSE;
        for ($written = 0; $written < $commandLen; $written += $fwrite) {
            $fwrite = fwrite($this->redis, substr($command, $written));
            if ($fwrite === FALSE || $fwrite == 0 && $lastFailed) {
                $this->connected = FALSE;
                throw new CredisException('Failed to write entire command to stream');
            }
            $lastFailed = $fwrite == 0;
        }
    }