Swoole First glass wool rockwool mineral woo

Source: Internet
Author: User
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.

  • 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.