Swoole Introduction-The Real PHP Web development Framework ____php

Source: Internet
Author: User
Tags php framework php web development smarty template

introduction of Swoole framework

Swoole is a very sophisticated PHP framework designed to effectively improve development efficiency. Swoole has a unified unique global object, similar to the Java registration tree, mount some commonly used objects, such as database, template engine, caching system, log system, event processing system, and so on. Can be easily invoked to quickly develop features. Using the Swoole framework, you only need to configure a config.php file, and you can invoke all the functionality of the framework by simply require config.php files in other PHP files.

Swoole through configuration files can be implemented in an easy to replace module-driven mode. such as database connection, can be very convenient to PDO MySQL mysqli between the replacement. Caching can be used Filecache, also can use Dbcache, also can use Memcache. Logs can be used in database logs or in system or file logs.

Code:

PHP code <?php require ' config.php ';   Auto Load Module $php->autoload (' db ', ' TPL ', ' cache ', ' Log ', ' event ', ' upload ');   Database query $res = $php->db->query (' SELECT * from Test ');   $one = $res->fetch ();   $all = $res->fetchall ();   Log $php->log->info (' hello ');   Cache $php->cache->get (' Cache_key ');   $hello = $php->cache->set (' Cache_key ', ' Me ', 1800);   Template $php->tpl->assign (' Hello ', $hello); $php->tpl->display (' index.html ');

Swoole provides a variety of library tools, form generation, input validation and filtering, login verification processing, JS Generation, AJAX support, debugging tools, client operations, URL merging and splitting tools.

Also provided are network classes (block, Select, event TCP, UDP Server & Client) that also provide some simple server protocol implementations (HTTP,CHAT,FTP,SMTP,POP3, etc.). There are also 2 JS class libraries, UI libraries and form validation. second, advanced application

The Swoole framework also provides the apps structure of MVC. Through the inheritance of Contoller, the encapsulation of business logic, the inheritance of model, the encapsulation of data operation, the view layer uses the Smarty template engine to implement the logical encapsulation of the page display.

Swoole Framework provides a powerful model class, Get,gets,set,sets,del,dels,put can be very convenient to implement the database additions and deletions, gets interface also has the function of automatic paging.

Swoole's SQL encapsulation is flexible, and it features that all SQL stitching uses arrays rather than object methods, so database query parameters can be seamlessly integrated with PHP's $_get,$_post,$_session,cache,cookie.

Code:

PHP code <?php $model = Createmodel (' Testmodel ');   $gets [' where '] [] = ' id>1 ';   $gets [' order '] = ' id desc ';   $gets [' limit '] = 10;   $gets [' where '] [] = ' category=10 ';   $gets [' select '] = ' id,title,name ']; $gets [' Leftjoin '] ... $data = $model->gets ($gets);

Swoole also has an ORM database operation, you can refer to the development manual.

The Swoole MVC URL route is done through a user-supplied function, which only needs to return the specific method of which controller is invoked. With the use of URL rewrite, you can customize any URL scheme, such as/controller/action/, controller_action.do,controller/action.do and so on. Or, like Django, completely use regular to specify the URL.

Event

Swoole provides an event-triggering system.

$php->event->raise (' sendsms ', $mobile, $sms _content);

This is a cool design, if you are configured to sync in a local test environment, then raise triggers a time to execute the handle function of the event. If it is a server environment and can be set to asynchronous, raise will only post an event to the queue server. Start a daemon in the background, get the event from the queue Server, and then use the handle function to process it.

Upload

Swoole can be unified processing of uploaded files, limit the upload size. Upload pictures, you can automatically compress the picture size, resulting in thumbnails. III. Deployment Modalities and stress testing

The Swoole framework can be deployed in a typical lamp environment in the same way as normal PHP. It can also be run using the HTTP server provided by Swoole itself.

Ordinary lamp way, because each request contains more PHP files, it is best to install APC, such as opcode cache. Stress tests, the same code, run less efficiently than thinkphp, but far beyond CodeIgniter, almost twice times more.

It is worth mentioning is to run the Swoole in the server way, the performance is extremely formidable. Is the same code Apache

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.