Home  >  Article  >  PHP Framework  >  How to combine Yii2 and Workerman

How to combine Yii2 and Workerman

尚
forward
2020-01-17 17:32:184351browse

How to combine Yii2 and Workerman

Related recommendations: "workerman Tutorial"

Put the content in the index.php of the Yii2 application in front of the Worker code, just to Change run to init:

<?php
require(__DIR__ . &#39;/../vendor/autoload.php&#39;);
require(__DIR__ . &#39;/../vendor/yiisoft/yii2/Yii.php&#39;);
require(__DIR__ . &#39;/../common/config/bootstrap.php&#39;);
require(__DIR__ . &#39;/config/bootstrap.php&#39;);
 
$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . &#39;/../common/config/main.php&#39;),
    require(__DIR__ . &#39;/../common/config/main-local.php&#39;),
    require(__DIR__ . &#39;/config/main.php&#39;),
    require(__DIR__ . &#39;/config/main-local.php&#39;)
);
 
(new yii\web\Application($config))->init(); //改为init

You can also continue to use the component method and directory structure of Yii2. Pay attention to a few points:

1. The debug component does not need to be loaded, and loading is meaningless because there is no request, so an error will be reported

2. It is best to define an index.php as the entrance to the entire workerman, so that some global variables such as YII_DEBUG can be initialized before main.php is loaded.

The above is the detailed content of How to combine Yii2 and Workerman. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete