Home > PHP Framework > Workerman > body text

How to combine Yii2 and Workerman

Release: 2021-02-01 12:07:06
forward
4369 people have browsed it

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
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template