PHP code example of deepziyu / yii2-swoole

1. Go to this page and download the library: Download deepziyu/yii2-swoole 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/ */

    

deepziyu / yii2-swoole example snippets



defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
defined('WEB_ROOT') or define('WEB_ROOT', dirname(__DIR__) . '/web'); //web目录的路径,用户访问的静态文件都放这里

  'task_worker_num' => 1,
        'log_file' => __DIR__.'/../runtime/logs/swoole.log',
        'log_level'=> 0,
        'chroot' => '/',
    ],
    'cacheTable' => function (){
        // swoole_table 需要提前启动,大小为 2 的次方
        return deepziyu\yii\swoole\cache\SwooleCache::initCacheTable(1024);
    },
    'bootstrap' => [
        'class' => 'deepziyu\yii\swoole\bootstrap\YiiWeb',
        'config' => function(){
            // 用闭包是为了延迟加载
            // 返回 Yii 的各个组件的配置
            ��还是逃不过一 run()
deepziyu\yii\swoole\server\Server::run($config);


      $models = User::find()->each(10);
      foreach ($models as $model) { // Hang up in this row
           $data[] = $model->toArray();
      }
  

      class OneModel extend ActiveRecord{
          public static function tableName()
          {
             return 'some-table do not exist';
          }
      }
      //导致进程终止
      $model = new OneModel([
          'some-att'=>'some-value',
      ]);
  

php swoole.php start|stop|reload|reload-task