A brief analysis of Ssdb PHP API

Source: Internet
Author: User

First, Introduction

Ssdb's PHP API provides a convenient interface for PHP development. git address https://github.com/ideawu/ssdb.git, SSDB Official document address http://ssdb.io/zh_cn/

Second, the SSDB class structure diagram

PHP interface source files in/api/php/ssdb.php

Third, SSDB network protocol

Message

' \ n ' Block  :'\ n'\ n'Size   := literal_integerdata   := Size_bytes_of_data

Request

Request: = cmd blocks*cmd     := Block

Request commands include:get, set, del, ...

Response

Response: = Status block*status   := Block

Response status codes include:ok, not_found, error, fail, client_error

Example

Connect to the SSDB server with a telnet or NC command, and enter the following code (ending with the last line of Blank lines):

3 Get 3 Key

You will see a response similar to this:

2 OK 3 Val

In send processing in the API, the CMD and Argus are sent to the server in the format of the network protocol. The relevant code is as follows

Private functionSend$data){                $ps=Array(); foreach($data  as $p){                        $ps[] =strlen($p); $ps[] =$p; }                $s=Join("\ n",$ps) . "\ n"; if($this-Debug) {                        Echo' > '.Str_replace(Array("\ r", "\ n"),Array(' \ r ', ' \ n '),$s) . "\ n"; }                Try{                         while(true){                                $ret= @fwrite($this->sock,$s); if($ret==false){                                        $this-Close (); Throw NewSsdbexception (' Connection lost '); }                                $s=substr($s,$ret); if(strlen($s) = = 0){                                         Break; }                                @Fflush($this-sock); }                }Catch(Exception $e){                        $this-Close (); Throw NewSsdbexception ($e-getMessage ()); }                return $ret; }

A brief analysis of Ssdb PHP API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.