Official definition:
Swoole: Redefining PHP
PHP's asynchronous, parallel, high-performance network communication engine, written in pure C, provides the PHP language for asynchronous multithreaded servers, asynchronous TCP/UDP network clients, asynchronous MySQL, asynchronous Redis, database connection pooling, Asynctask, Message Queuing, millisecond timers, Asynchronous file read-write, asynchronous DNS query. Swoole built-in Http/websocket server side/client, Http2.0 server side.
Swoole can be widely used in the Internet, mobile communications, enterprise software, cloud computing, online games, Internet of things, car networking, smart home and other fields. The use of Php+swoole as a network communication framework can greatly improve the efficiency of enterprise IT research and development teams and focus on the development of innovative products.
Swoole expansion Installation and case Source: http://wiki.swoole.com/wiki/page/6.html
Simple case:
Phpclassserver{Private$serv; Publicfunction__construct () {$this->serv =NewSwoole_server ("0.0.0.0", 9501); $this->serv->set (Array( ' Worker_num ' = 8, ' daemonize 'false, ' max_request ' = 10000, ' Dispatch_mode ' and ' 2, ' debug_mode ' + 1 )); $this->serv->on (' Start ',Array($this, ' OnStart ')); $this->serv->on (' Connect ',Array($this, ' OnConnect ')); $this->serv->on (' Receive ',Array($this, ' OnReceive ')); $this->serv->on (' Close ',Array($this, ' OnClose ')); $this->serv->start (); } PublicfunctionOnStart ($serv) { Echo"Start\n"; } PublicfunctionOnConnect ($serv,$FD,$from _id) { $serv->send ($FD, "Hello {$FD}!"); } PublicfunctionOnReceive (swoole_server$serv,$FD,$from _id,$data) { Echo"Get Message from Client {$FD}:{$data}\n "; } PublicfunctionOnClose ($serv,$FD,$from _id) { EchoThe Client {$FD} Close Connection\n "; }}//Start the server$server=NewServer ();
Phpclassclient{Private$client; Publicfunction__construct () {$this->client =Newswoole_client (SWOOLE_SOCK_TCP); } PublicfunctionConnect () {if(!$this->client->connect ("127.0.0.1", 9501, 1)) { Echo"Error: {$fp->errmsg}[{$fp->errcode}]\n "; } $message=$this->client->recv (); Echo"Get Message from server:{$message}\n "; fwrite(STDOUT, "Please enter the message:"); $msg=Trim(fgets(STDIN)); $this->client->send ($msg); }}$client=NewClient ();$client->connect ();
Open two terminal inputs respectively: PHP server.php php client.php to see the effect!
The above describes the Swoole, including the wool,ole aspects of the content, I hope that the PHP tutorial interested in a friend helpful.