Home >PHP Framework >Swoole >Take you to learn the swoole framework in three minutes
I’ve been learning about swoole recently, so I’ll write down some thoughts. There are many open source frameworks based on swoole. The advantages and disadvantages can be found in Baidu. If websockets and consumer queues are used, it is a good choice to choose a framework based on swoole. Well, without further ado, Wu Daxian will introduce a simple introduction to swoole
Recommended (free):swoole
##Textswoole has two parts. One is a PHP extension, developed in C, which is the core. The other is a framework, like Yii, TP, and Laravel, which is written in PHP code. The swoole extension itself provides web server functionality and can replace php-fpm. And if you only use the swoole framework, it can run in web servers such as nignx and apache like other PHP frameworks. The swoole framework, like the PHP framework, is suitable for web development. The swoole extension provides a lower-level server communication mechanism, which can use UDP, TCP and other protocols, not just http. The installation method is also different. The swoole extension is installed like other PHP extensions. You can use pecl or compile and install it. The swoole framework can be installed after being introduced with composer, or you can manually include/require after downloading the source code. In addition, the swoole framework relies on the swoole extension and is an application example of the swoole extension. Framework-Swoole extension-Swoole Document Center http://wiki.swoole.com/wiki/page/p-framework.htmlSwoole extension is the foundation. Based on swoole extension, you can do Develop multiple frameworks, not just web frameworks. The framework uses a unique interface object mechanism. The first step in calling the framework, require('config.php'); must first include config.php, and then the $php object will be generated. If it is in Controller, Model, or View, call it through $this->swoole. If it is in a function or other included program, it is referenced through global $php.Database interface | |
Cache system interface | |
Smarty template engine interface | |
Call the Model object interface | |
MVC structure data | |
Plug-in system interface |
$ROOT/apps
$ROOT /apps: Application code, the code in this directory is public, including classes, configurations, templates, controllers, Models, etc. Static files such as js, css, jpg, html, etc. must not be placed in this directory. They must all be .php files. This directory does not allow direct http access.
Ø $ROOT/apps/controllers Web application controller class code
Ø $ROOT/apps/models Data model encapsulation class code
Ø $ROOT/apps/ configs configuration file, access the
Ø ROOT/apps/classes class library through $php->config['db']['master'], where all user-defined classes are stored, which must comply with psr -0 specification, the file name must be {class name}.php, and the top-level namespace must be App
Ø $ROOT/apps/templates template file directory
² Namespace: such as new App\Hello\Test class, will be mapped to $ROOT/apps/classes/Hello/Test.php
² Configuration file: such as $php->config['db'][ 'master'] or Swoole::getInstance()->config['db']['master'] will be mapped to the $ROOT/apps/configs/db.php file. An array must be returned in db.php, and the key is master.
² Data model: model('UserInfo') or $php->model->UserInfo will be mapped to $ROOT/apps/models/UserInfo.php
$ROOT/static
Static file directory, such as js, css, jpg, html, etc.
$ROOT/index.php
The single entry file of the web website can be placed directly in the root directory, or a separate directory can be created for storage, such as $ROOT/webroot/index.php
$ROOT/server.php
Server program startup entrance.
ControllerController² Code is placed in the apps\controllers directory
² The first letter of the class name must be capitalized
² Must inherit from Swoole\Controller
The above is the detailed content of Take you to learn the swoole framework in three minutes. For more information, please follow other related articles on the PHP Chinese website!