我在workerman使用模型时会报错,在webman中能正常使用
$tcp_worker->onMessage = function ($connection, $data) { Department::get();//这里会报对象没有初始化 $connection->send('Received: ' . $data); };
请发原始的完整报错
PS D:\php7\www\webman\process> php WorkermanTcpService.php start ---------------------------------------------- WORKERMAN ----------------------------------------------- Workerman version:4.1.15 PHP version:8.2.4 ----------------------------------------------- WORKERS ------------------------------------------------ worker listen processes status none tcp://0.0.0.0:2016 1 [ok] Error: Call to a member function connection() on null in D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php:1820 Stack trace:
PS D:\php7\www\webman\process>
应该是没初始化数据库 https://github.com/illuminate/database 参考他们文档初始化
在webman里会自动初始化
请发原始的完整报错
PS D:\php7\www\webman\process> php WorkermanTcpService.php start
---------------------------------------------- WORKERMAN -----------------------------------------------
Workerman version:4.1.15 PHP version:8.2.4
----------------------------------------------- WORKERS ------------------------------------------------
worker listen processes status
none tcp://0.0.0.0:2016 1 [ok]
Error: Call to a member function connection() on null in D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php:1820
Stack trace:
0 D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php(1786): Illuminate\Database\Eloquent\Model::resolveConnection()
1 D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php(1577): Illuminate\Database\Eloquent\Model->getConnection()
2 D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php(1496): Illuminate\Database\Eloquent\Model->newBaseQueryBuilder()
3 D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php(1532): Illuminate\Database\Eloquent\Model->newModelQuery()
4 D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php(1485): Illuminate\Database\Eloquent\Model->newQueryWithoutScopes()
5 D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php(2335): Illuminate\Database\Eloquent\Model->newQuery()
6 D:\php7\www\webman\vendor\illuminate\database\Eloquent\Model.php(2347): Illuminate\Database\Eloquent\Model->__call()
7 D:\php7\www\webman\process\WorkermanTcpService.php(16): Illuminate\Database\Eloquent\Model::__callStatic()
8 D:\php7\www\webman\vendor\workerman\workerman\Connection\TcpConnection.php(667): {closure}()
9 D:\php7\www\webman\vendor\workerman\workerman\Events\Select.php(311): Workerman\Connection\TcpConnection->baseRead()
10 D:\php7\www\webman\vendor\workerman\workerman\Worker.php(1488): Workerman\Events\Select->loop()
11 D:\php7\www\webman\vendor\workerman\workerman\Worker.php(1405): Workerman\Worker::forkWorkersForWindows()
12 D:\php7\www\webman\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers()
13 D:\php7\www\webman\process\WorkermanTcpService.php(21): Workerman\Worker::runAll()
14 {main}
PS D:\php7\www\webman\process>
应该是没初始化数据库
https://github.com/illuminate/database
参考他们文档初始化
在webman里会自动初始化