First understanding of Swoole in PHP, first understanding of PHPSwoole

Source: Internet
Author: User
Tags php server php websocket website performance

First understanding of Swoole in PHP, first understanding of PHPSwoole

Swoole is a PHP advanced Web development framework. It is not designed to improve website performance, but to improve website development efficiency. Minimum Performance Loss in exchange for maximum development efficiency. Using the Swoole framework, you can develop a complex Web function in a short time.

Official definition:

Swoole: redefine PHP

PHP's asynchronous, parallel, and high-performance network communication engine, written in pure C language, provides PHP-language asynchronous multi-thread servers, asynchronous TCP/UDP network clients, asynchronous MySQL, asynchronous Redis, database Connection Pool, AsyncTask, message queue, millisecond timer, asynchronous file read/write, asynchronous DNS query. Swoole has built-in Http/WebSocket server/client and Http2.0 server.

Swoole can be widely used in the Internet, mobile communication, enterprise software, cloud computing, online games, Iot, IOV, Smart Home, and other fields. Using PHP + Swoole as the network communication framework can greatly improve the efficiency of enterprise it r & D teams and focus more on developing innovative products.

Swoole extension installation and case study Source: http://wiki.swoole.com/wiki/page/6.html

Simple case:

<? Phpclass Server {private $ serv; public function _ construct () {$ this-> serv = new swoole_server ("0.0.0.0", 9501 ); $ this-> serv-> set (array ('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-> s Erv-> 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 the server $ Server = new server (); <? Phpclass Client {private $ client; public 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, "Enter the Message:"); $ msg = trim (fgets (STDIN )); $ this-> client-> send ($ msg) ;}$ client = new Client (); $ client-> connect ();

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

Swoole features

It includes the following features:

1. Data Query similar to ORM. It provides an SQL package to seamlessly integrate MySQL SQL with PHP Array, session, and Cache.

2. Application MVC layered structure, effective program structural layering, improving program maintainability and scalability, achieving low coupling, and interface-based development.

3. Integrate a large number of practical functions, such as convenient database operations, template operations, cache operations, system configuration, form processing, paging, data calling, Dictionary operations, and upload processing, content editing and debugging.

4. template-the data reflection system can call data directly in the template and provide many tags. However, you can update and maintain the website only by modifying the template without modifying the program.

Other functions

1. Swoole contains a large number of classes and provides many function extensions. Basically, most of the function classes that can be used in Web development can be found in the Swoole framework.

2. Swoole has a plug-in system, Fckeditor, Adodb, pscws Chinese word segmentation, Chinese full text index system, the latest Key-Value database ideas, TokyoTyrant, which can infinitely expand the functions of the framework.

Articles you may be interested in:
  • Example of using swoole to expand php websocket
  • Analysis of the Timer features of the PHP Swoole Timer
  • Example of php asynchronous multi-thread swoole usage
  • How to install swoole extension in php
  • Swoole-1.7.22 version released to fix PHP7 Problems
  • Use php + swoole to Update client data in real time (1)
  • PHP + swoole implement simple multi-person online chat group

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.