环境:Webman v1.5.1
DI版本:composer require psr/container ^1.1.1 php-di/php-di ^6 doctrine/annotations ^1.14
namespace app\controller;
use app\model\Test;
use support\Request;
use support\Db;
use support\Redis;
class IndexController
{
protected array $key = [];
protected Test $test;
public function __construct(Test $test)
{
$this->key[] = "this is index _construct".PHP_EOL;
$this->test = $test;
}
public function index(Request $request)
{
Redis::setEx('key', 60, randomChars());
$key = Redis::get('key');
return json(['key' => count($this->key), 'x' => $key]);
}
Workerman[start.php] start in DEBUG mode
--------------------------------------------------------- WORKERMAN ---------------------------------------------------------
Workerman version:4.1.9 PHP version:8.1.12 Event-Loop:\Workerman\Events\Event
---------------------------------------------------------- WORKERS ----------------------------------------------------------
proto user worker listen processes status
tcp a webman http://0.0.0.0:8787 1 [OK]
tcp a monitor none 1 [OK]
tcp a plugin.webman.redis-queue.consumer none 1 [OK]
tcp a plugin.webman.redis-queue.consumer.inventory none 1 [OK]
tcp a plugin.commerce.order.waiting:cancel.toQueue none 1 [OK]
-----------------------------------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
DI\Definition\Exception\InvalidDefinition: Entry "process\Monitor" cannot be resolved: Parameter $monitorDir of __construct() has no value defined or guessable
Full definition:
Object (
class = process\Monitor
lazy = false
__construct(
$monitorDir = #UNDEFINED#
$monitorExtensions = #UNDEFINED#
$options = (default value) array (
)
)
) in /api/vendor/php-di/php-di/src/Definition/Exception/InvalidDefinition.php:19
Stack trace:
#0 /api/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(156): DI\Definition\Exception\InvalidDefinition::create(Object(DI\Definition\ObjectDefinition), 'Entry "process\\...')
#1 /api/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(71): DI\Definition\Resolver\ObjectCreator->createInstance(Object(DI\Definition\ObjectDefinition), Array)
#2 /api/vendor/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(71): DI\Definition\Resolver\ObjectCreator->resolve(Object(DI\Definition\ObjectDefinition), Array)
#3 /api/vendor/php-di/php-di/src/Container.php(390): DI\Definition\Resolver\ResolverDispatcher->resolve(Object(DI\Definition\ObjectDefinition), Array)
#4 /api/vendor/php-di/php-di/src/Container.php(199): DI\Container->resolveDefinition(Object(DI\Definition\ObjectDefinition), Array)
#5 /api/vendor/workerman/webman-framework/src/support/Container.php(46): DI\Container->make('process\\Monitor', Array)
#6 /api/support/helpers.php(468): support\Container::__callStatic('make', Array)
#7 /api/vendor/workerman/workerman/Worker.php(2488): {closure}(Object(Workerman\Worker))
#8 /api/vendor/workerman/workerman/Worker.php(1627): Workerman\Worker->run()
#9 /api/vendor/workerman/workerman/Worker.php(1423): Workerman\Worker::forkOneWorkerForLinux(Object(Workerman\Worker))
#10 /api/vendor/workerman/workerman/Worker.php(1397): Workerman\Worker::forkWorkersForLinux()
#11 /api/vendor/workerman/workerman/Worker.php(560): Workerman\Worker::forkWorkers()
#12 /api/vendor/workerman/webman-framework/src/support/App.php(131): Workerman\Worker::runAll()
#13 /api/start.php(8): support\App::run()
#14 {main}
worker[monitor:95878] exit with status 64000
经过观察,把process\Monitor的constructor参数默认值配置到 dependence.php 即可;
如下:
原配置config/process 中monitor节点的配置不需要变更;