public function send($command, $data = '')
    {
        // Reset state - ensure clean start.
        $this->reset();

        // Check if command is allowed
        if (in_array($command, $this->allowedCommands) === false) {
            throw new Exception(
                sprintf('The command "%s" is not allowed!', $command)
            );
        }

        // Get socket
        $socket = $this->connect($this->getHost(), $this->getPort());

        // The buffer to be filled with response
        $buffer = '';

        // Dispatch command in some different ways ... depending on command ...
        fwrite($socket, $data);

        // Fetch while receiving data ...
        while ((!feof($socket))) {

            // Fetch Bytes from socket ...
            $buffer .= fgets($socket, self::SOCKET_READ_FETCH_BYTES);

            // Response max. 64 Bit value = 8 Bytes - We reed 256 Bytes at once so one round is definitive enough ;)
            if ($command === self::COMMAND_INCR || $command === self::COMMAND_DECR) {
                break;
            }

            foreach ($this->sigsEnd as $sigEnd) {
                if (preg_match('/^' . $sigEnd . '/imu', $buffer)) {
                    break 2;
                }
            }
        }

        // Check if response is parseable ...
        if ($this->checkResponse($buffer) !== true) {
            throw new Exception(
                sprintf(
                    'Error "%s" while sending command "%s" to host "%s"',
                    $this->getLastResponse(),
                    $command,
                    $this->getHost() . ':' . $this->getPort()
                )
            );
        }

        // Parse the response and return result ...
        return $this->parseResponse($command, $buffer);
    }
public function send($command, $data = '')
    {
        // Reset state - ensure clean start.
        $this->reset();

        // Check if command is allowed
        if (in_array($command, $this->allowedCommands) === false) {
            throw new Exception(
                sprintf('The command "%s" is not allowed!', $command)
            );
        }

        // Get socket
        $socket = $this->connect($this->getHost(), $this->getPort());

        // The buffer to be filled with response
        $buffer = '';

        // Dispatch command in some different ways ... depending on command ...
        fwrite($socket, $data);

        // Fetch while receiving data ...
        while ((!feof($socket))) {

            // Fetch Bytes from socket ...
            $buffer .= fgets($socket, self::SOCKET_READ_FETCH_BYTES);

            // Response max. 64 Bit value = 8 Bytes - We reed 256 Bytes at once so one round is definitive enough ;)
            if ($command === self::COMMAND_INCR || $command === self::COMMAND_DECR) {
                break;
            }

            foreach ($this->sigsEnd as $sigEnd) {
                if (preg_match('/^' . $sigEnd . '/imu', $buffer)) {
                    break 2;
                }
            }
        }

        // Check if response is parseable ...
        if ($this->checkResponse($buffer) !== true) {
            throw new Exception(
                sprintf(
                    'Error "%s" while sending command "%s" to host "%s"',
                    $this->getLastResponse(),
                    $command,
                    $this->getHost() . ':' . $this->getPort()
                )
            );
        }

        // Parse the response and return result ...
        return $this->parseResponse($command, $buffer);
    }
public function send ( $ command , $ data = '' ) { // Reset state - ensure clean start. $ this -> reset ( ) ; // Check if command is allowed if ( in_array ( $ command , $ this -> allowedCommands ) === false ) { throw new Exception ( sprintf ( 'The command "%s" is not allowed!' , $ command ) ) ; } // Get socket $ socket = $ this -> connect ( $ this -> getHost ( ) , $ this -> getPort ( ) ) ; // The buffer to be filled with response $ buffer = '' ; // Dispatch command in some different ways ... depending on command ... fwrite ( $ socket , $ data ) ; // Fetch while receiving data ... while ( ( ! feof ( $ socket ) ) ) { // Fetch Bytes from socket ... $ buffer .= fgets ( $ socket , self :: SOCKET_READ_FETCH_BYTES ) ; // Response max. 64 Bit value = 8 Bytes - We reed 256 Bytes at once so one round is definitive enough ;) if ( $ command === self :: COMMAND_INCR || $ command === self :: COMMAND_DECR ) { break ; } foreach ( $ this -> sigsEnd as $ sigEnd ) { if ( preg_match ( '/^' . $ sigEnd . '/imu' , $ buffer ) ) { break 2 ; } } } // Check if response is parseable ... if ( $ this -> checkResponse ( $ buffer ) !== true ) { throw new Exception ( sprintf ( 'Error "%s" while sending command "%s" to host "%s"' , $ this -> getLastResponse ( ) , $ command , $ this -> getHost ( ) . ':' . $ this -> getPort ( ) ) ) ; } // Parse the response and return result ... return $ this -> parseResponse ( $ command , $ buffer ) ; }
Sends a command to a Memcached instance and returns the parsed result.

@param string $command The command to send to Memcached daemon
@param string $data    The data to pass with command

@author Benjamin Carl <opensource@clickalicious.de>
@return mixed|array The result from Memcached daemon
@access public
@throws \Clickalicious\Memcached\Exception
Sends a command to a Memcached instance and returns the parsed result .