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__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/../common/config/bootstrap.php'); require(__DIR__ . '/config/bootstrap.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/../common/config/main.php'), require(__DIR__ . '/../common/config/main-local.php'), require(__DIR__ . '/config/main.php'), require(__DIR__ . '/config/main-local.php') ); (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!