tsingsun / yii2-swoole

make yii2 project runing on swoole
BSD 3-Clause "New" or "Revised" License
162 stars 23 forks source link

写了一个demo,但是跑不下去,我把步骤列出来,希望能够帮忙解决。 #4

Closed wanglongxiang closed 5 years ago

wanglongxiang commented 5 years ago

我用该组件的目的是为了解决yii2中的redis没有连接池的问题,找了很多组件,没找到合适的,我看到这个组件说支持redis连接池,所以就用了,希望大家如果有发现好yii2相关的redis连接池组件请留言给我,下面继续说步骤。

环境:系统是Linux Ubuntu 16.04,yii是2.0.12,swoole是2.2,PHP是7.0.32,nginx是1.10.3

步骤1、创建http_server.php文件 代码如下: ` use \tsingsun\swoole\server\Server;

defined('WEBROOT') or define('WEBROOT', DIR); defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); //协程与非协程的切换 defined('COROUTINE_ENV') or define('COROUTINE_ENV', true);

require(DIR . '/../vendor/autoload.php'); $config = [ 'class'=>'tsingsun\swoole\server\HttpServer', //Swoole的配置,根据实际情况配置 'setting' => [ 'daemonize'=>0, 'max_coro_num'=>3000, 'reactor_num'=>1, 'worker_num'=>1, 'task_worker_num'=>1, 'pid_file' => DIR . '/../runtime/testHttp.pid', 'log_file' => DIR.'/../runtime/logs/swoole.log', 'debug_mode'=> 1, 'user'=>'tsingsun', 'group'=>'staff', ], ];

Server::run($config,function (Server $server){ $starter = new \tsingsun\swoole\bootstrap\WebApp($server); //初始化函数独立,为了在启动时,不会加载Yii相关的文件,在库更新时采用reload平滑启动服务器 $starter->init = function (\tsingsun\swoole\bootstrap\BaseBootstrap $bootstrap) { //需要使用Yii-Swoole项目的Yii文件, require(DIR . '/../vendor/tsingsun/yii2-swoole/src/Yii.php'); //原项目的配置文件引入 $config = yii\helpers\ArrayHelper::merge( require(DIR . '/../vendor/tsingsun/yii2-swoole/tests/config/main.php'), require(DIR . '/../vendor/tsingsun/yii2-swoole/tests/config/main-local.php') ); $bootstrap->appConfig = $config; }; $server->bootstrap = $starter; $server->start(); }); ` 注:代码基本上和原始代码相同,只是改了路径而已。 步骤2、运行sudo php http_server.php start命令 然后报错。 错误内容如下: thrown in [no active file] on line 0 PHP Warning: require(我的linux项目路径/vendor/tsingsun/yii2-swoole/src/Yii.php): failed to open stream: No such file or directory in 我的linux项目路径/web/http_server.php on line 41 PHP Fatal error: require(): Failed opening required '我的linux项目路径/vendor/tsingsun/yii2-swoole/src/Yii.php' (include_path='.:/usr/share/php') in 我的linux项目路径/web/http_server.php on line 41 PHP Fatal error: Uncaught Exception: SeasLog Invalid Log File - /var/log/www/default/20181009.log in [no active file]:0 Stack trace:

0 {main}

注:路径不论我怎么改还总是报错,除非我把require删掉或者拿到run()方法的外部此错误就没有了,但是会出现其他错误,希望作者大神能帮忙解决我的疑问,谢谢。

tsingsun commented 5 years ago

看看 .vendor下是项目代码是否正确获取得.不然你用master分支试试,因为前阵子composer中国出现问题,不知是否会影响代码获取.还有,你的配置文件位置怪怪的.为什么要用项目的test目录下的配置文件呢?