krissss / yii2-web-msg-sender

Yii2 web msg sender with workerman
3 stars 1 forks source link

启动服务报错,能帮忙定位一下吗,谢谢 #1

Closed cougar999 closed 6 years ago

cougar999 commented 6 years ago

Exception 'yii\base\InvalidConfigException' with message 'Unknown component ID: web-msg-sender'

in /home/verttech/sites/msg/vendor/yiisoft/yii2/di/ServiceLocator.php:139

Stack trace:

0 /home/verttech/sites/msg/vendor/yiisoft/yii2/base/Module.php(724): yii\di\ServiceLocator->get('web-msg-sender', true)

1 /home/verttech/sites/msg/vendor/kriss/yii2-web-msg-sender/src/WebMsgSender.php(133): yii\base\Module->get('web-msg-sender')

2 /home/verttech/sites/msg/vendor/kriss/yii2-web-msg-sender/src/Service.php(28): kriss\webMsgSender\WebMsgSender::getComponent()

3 /home/verttech/sites/msg/vendor/kriss/yii2-web-msg-sender/src/ServiceController.php(10): kriss\webMsgSender\Service->__construct()

4 [internal function]: kriss\webMsgSender\ServiceController->actionStart()

5 /home/verttech/sites/msg/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

6 /home/verttech/sites/msg/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)

7 /home/verttech/sites/msg/vendor/yiisoft/yii2/console/Controller.php(144): yii\base\Controller->runAction('start', Array)

8 /home/verttech/sites/msg/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('start', Array)

9 /home/verttech/sites/msg/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('web-msg-sender-...', Array)

10 /home/verttech/sites/msg/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('web-msg-sender-...', Array)

11 /home/verttech/sites/msg/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))

12 /home/verttech/sites/msg/yii(20): yii\base\Application->run()

13 {main}

krissss commented 6 years ago

component 没配置,应该是你只配置了 web 的 component,控制台(console)的 component 没配置

cougar999 commented 6 years ago

`<?php $params = require DIR . '/params.php'; $db = require DIR . '/db.php';

$config = [ 'id' => 'basic-console', 'basePath' => dirname(DIR), 'bootstrap' => ['log'], 'controllerNamespace' => 'app\commands', 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'db' => $db, ], 'params' => $params, 'controllerMap' => [ 'web-msg-sender-service' => [ 'class' => \kriss\webMsgSender\ServiceController::class, ], ], ];`

这样不对吗

cougar999 commented 6 years ago

哦,我这个用的是basic版的Yii2, 没有console/config, 只在config里面有个console.php,跟这个有关系?

krissss commented 6 years ago

是在 console.php 下配置的,在 components 下配置:

WebMsgSender::COMPONENT_NAME => [
    'class' => WebMsgSender::class,
    'pushApiClientHost' => 'localhost',
    'logCategory' => 'webMsgSender',
],
cougar999 commented 6 years ago

这个我刚才配置了,结果提示我的是unknown command $php yii web-msg-sender-service/start Unknown command: web-msg-sender-service/start Usage: php yourfile [mode] Commands: start Start worker in DEBUG mode. Use mode -d to start in DAEMON mode. stop Stop worker. Use mode -g to stop gracefully. restart Restart workers. Use mode -d to start in DAEMON mode. Use mode -g to stop gracefully. reload Reload codes. Use mode -g to reload gracefully. status Get worker status. Use mode -d to show live status. connections Get worker connections.

krissss commented 6 years ago

完整的配置发一下

krissss commented 6 years ago

linux 环境下的?

krissss commented 6 years ago

linux 环境下使用下方这种配置,去掉 controllerMap,然后编写一个php文件,比如:workman.php,内容如下,(前半部yii的配置按照你的项目去调整)

<?php

defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');

require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/console/config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/common/config/main.php'),
    require(__DIR__ . '/common/config/main-local.php'),
    require(__DIR__ . '/console/config/main.php'),
    require(__DIR__ . '/console/config/main-local.php')
);

$application = (new yii\console\Application($config))->init();

new \kriss\webMsgSender\Service();

\Workerman\Worker::runAll();

然后执行:php workman.php

cougar999 commented 6 years ago

web.php

` use kriss\webMsgSender\WebMsgSender; $params = require DIR . '/params.php'; $db = require DIR . '/db.php';

$config = [ 'id' => 'basic', 'name' => 'XXX', 'basePath' => dirname(DIR), 'bootstrap' => ['log'], 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'timeZone' => 'Australia/Melbourne', 'components' => [ 'request' => [ 'cookieValidationKey' => '4tqG6ZExNRgRhTF1uT4LBXvp-yJGRojR', ], 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'errorHandler' => [ 'errorAction' => 'site/error', ], 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'useFileTransport' => true, ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'db' => $db, 'authManager' => [ 'class' => 'yii\rbac\DbManager', // 或者使用 'yii\rbac\PhpManager' ], "urlManager" => [
"enablePrettyUrl" => true,
"enableStrictParsing" => false,
"showScriptName" => false,
"suffix" => "",
"rules" => [
"<controller:\w+>/<id:\d+>"=>"/view",
"<controller:\w+>/<action:\w+>"=>"/"
], ], WebMsgSender::COMPONENT_NAME => [ 'class' => WebMsgSender::class, 'pushApiClientHost' => 'localhost', 'logCategory' => 'webMsgSender', 'pushMsgTemplate' => '{content}', 'socketPort' => 22311, 'innerHttpPort' => 28211, ], ], 'modules' => [ 'admin' => [ 'class' => 'mdm\admin\Module', ], 'user' => [ 'class' => 'dektrium\user\Module', 'enableRegistration' => false, 'enableConfirmation' => false, 'enablePasswordRecovery' => false, //'admins' => ['charles'] 'adminPermission' => 'Administrator' ], ],

'params' => $params,

];

return $config; `

cougar999 commented 6 years ago

console.php

`<?php use kriss\webMsgSender\WebMsgSender; $params = require DIR . '/params.php'; $db = require DIR . '/db.php';

$config = [ 'id' => 'basic-console', 'basePath' => dirname(DIR), 'bootstrap' => ['log'], 'controllerNamespace' => 'app\commands', 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'db' => $db, WebMsgSender::COMPONENT_NAME => [ 'class' => WebMsgSender::class, 'pushApiClientHost' => 'localhost', 'logCategory' => 'webMsgSender', 'pushMsgTemplate' => '{content}', 'socketPort' => 2020, 'innerHttpPort' => 2023, ], ], 'params' => $params, 'controllerMap' => [ 'web-msg-sender-service' => [ 'class' => \kriss\webMsgSender\ServiceController::class, ], ],

];

return $config; `

我在试着你上面的方法

cougar999 commented 6 years ago

PHPSocketIO 打开了,在打开Webserver的时候出错了。 ` yii\base\ErrorException: stream_socket_server(): unable to connect to tcp://0.0.0.0:28211/ (Failed to parse address "0.0.0.0:28211/") in /home/verttech/sites/msg/vendor/workerman/workerman/Worker.php:2178 Stack trace:

0 [internal function]: yii\base\ErrorHandler->handleError(2, 'stream_socket_s...', '/home/verttech/...', 2178, Array)

1 /home/verttech/sites/msg/vendor/workerman/workerman/Worker.php(2178): stream_socket_server('tcp://0.0.0.0:2...', 0, 'Failed to parse...', 12, Resource id #104)

2 /home/verttech/sites/msg/vendor/kriss/yii2-web-msg-sender/src/Service.php(76): Workerman\Worker->listen()

3 [internal function]: kriss\webMsgSender\Service->kriss\webMsgSender{closure}(Object(Workerman\Worker))

`

krissss commented 6 years ago

web 处的两个端口号要保持和 console 的一致,原则上web 和 console 的 WebMsgSender::COMPONENT_NAME 的配置是一模一样的

cougar999 commented 6 years ago

是的,我写的是一样的,上面那个就是为了贴代码改了一下

cougar999 commented 6 years ago

用这个扩展还是没有成功,我用别的方法解决了