Initial knowledge of PHP swoole, phpswoole_php tutorial

Source: Internet
Author: User
Tags php language php framework php websocket

First knowledge of Swoole in PHP, first knowledge of phpswoole


Swoole is a PHP advanced Web development Framework that is not designed to improve the performance of the site, but to improve the productivity of the site. Minimum performance loss in exchange for maximum development efficiency. Using the Swoole framework, a complex web feature can be developed in a very short period of time.

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:

<?phpclass server{private $serv;p ublic function __construct () {$this->serv = new Swoole_server ("0.0.0.0", 9501); $ This->serv->set (' worker_num ' = 8, ' daemonize ' = False, ' max_request ' = = 10000, ' dispatch_mode ' = > 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 ();} Public Function OnStart ($serv) {echo "start\n";} Public Function OnConnect ($serv, $FD, $from _id) {$serv->send ($fd, "Hello {$fd}!");} Public Function OnReceive (Swoole_server $serv, $FD, $from _id, $data) {echo ' Get Message from Client {$fd}:{$data}\n ";} Public Function OnClose ($serv, $FD, $from _id) {echo "Client {$FD} close connection\n"} Start server $server = new server (); <?phpclass client{private $client;p ublic function __construct () {$this->client = new Swoole_client (SwooLE_SOCK_TCP);} Public Function Connect () {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 message:"); $msg = Trim (Fgets (STDIN)); $this->client->send ($msg);}}  $client = new Client (); $client->connect ();

Open two terminal inputs respectively: PHP server.php php client.php to see the effect!

Swoole Function Introduction

Includes the following features:

1. ORM-like data query, provide SQL wrapper, let MySQL SQL and PHP array, session, cache seamlessly combined.

2, the application MVC layered structure, the effective program structure stratification, enhances the program maintainability and the Expansibility, realizes the low coupling, based on the interface development.

3, integration of a large number of practical functions, such as convenient database operations, template operations, caching operations, system configuration, form processing, paging, data calls, dictionary operations, upload processing, content editing, debugging and so on.

4, template-Data reflection system, you can call the data directly in the template, provide a lot of tags, but no need to modify the program, only modify the template, you can achieve the site of various types of maintenance work.

A few additional features

1, Swoole contains a large number of classes, providing a large number of functional extensions, basically web development can use the function of the class, most of them can be found in the Swoole framework.

2, Swoole has a plug-in system, Fckeditor, Adodb, PSCWS Chinese word segmentation, Chinese full-text indexing system, the latest Key-value database ideas, tokyotyrant, can infinitely expand the framework of the function.

Articles you may be interested in:

    • Extending the PHP websocket example with Swoole
    • PHP Framework swoole Timer feature Analysis
    • PHP Asynchronous multithreaded Swoole Usage example
    • How to install Swoole extensions in PHP
    • Swoole-1.7.22 version released to fix PHP7 related issues
    • Real-time update of client data using Php+swoole (i)
    • Php+swoole realizes simple multiplayer online chat mass.

http://www.bkjia.com/PHPjc/1117023.html www.bkjia.com true http://www.bkjia.com/PHPjc/1117023.html techarticle The first knowledge of php swoole, phpswoole swoole is a PHP advanced Web development Framework, the framework is not to improve the performance of the site, is to improve the efficiency of the development of the site. Minimal performance loss ...

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