PHP code example of dionyang25 / yii2-swoole-plugin

1. Go to this page and download the library: Download dionyang25/yii2-swoole-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dionyang25 / yii2-swoole-plugin example snippets


    composer 

    'yii2Swoole'=>[
        'class'=>'yii2Swoole\Server'
    ]

    'yii2Swoole'=>[
        'class'=>'yii2Swoole\Server',
        'config'=>[
              'daemonize'=>0,
              'reactor_num'=>4,
              'worker_num'=>20,
              'max_request' => 100,
              'pid_file'=> __DIR__ . '/../../../runtime/server.pid'
        ]
    ]

defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_ENV') or define('YII_ENV', 'dev');
$config = \yii\helpers\ArrayHelper::merge(
    


namespace app\commands;
use yii\console\Controller;
use Yii;
/**
 * @author DionYang
 * @since 2.0
 */
class HelloController extends Controller
{
    /**
     * This command echoes what you have entered as the message.
     * @param string $message the message to be echoed.
     */
    public function actionIndex()
    {
        $server =Yii::$app->yii2Swoole;
        $server->entrance_file = __DIR__.'/../php-backstreet-api/index-test.php';
        $server->run();
    }

    public function actionStop()
    {
        $this->stdout('Already Stop'.PHP_EOL);
        Yii::$app->yii2Swoole->appStop();
    }
}

./yii hello //启动
./yii hello/stop //终止
nginx
location ^~ /php-backstreet-api {
    root /Users/admin/www/php-backstreet-api;
  
    location ~ \.(css|js|jpg|png|gif)$ {
            root /Users/admin/www;
    }
    location ~ / {
        try_files $uri $uri/ /php-backstreet-api/index.php$is_args$args;
        #fastcgi_pass   127.0.0.1:9003;
        #fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        #