单文件怎么引用tp6的数据库操作

CC.
<?php
use Workerman\Worker;
use Workerman\Connection\AsyncTcpConnection;
use Workerman\Lib\Timer;
use app\date\model\SystemNode;
require_once __DIR__ . '/vendor/autoload.php';
/**
 * Worker 命令行类
 */
 $worker = new Worker();
 $worker->onWorkerStart = function($worker){
$conC_url="ws://xxx";
$con_url="ws://xxx";
//配置
$conC = new AsyncTcpConnection($conC_url);$conC->transport = 'ssl';
// // 建立连接
$conC->onConnect = function($connection) {
SystemNode::mk()->where('')->update();
};
// 远程websocket服务器发来消息时
$conC->onMessage = function($connection, $data){
print_r($data."\n");
};
// 连接上发生错误时,一般是连接远程websocket服务器失败错误
$conC->onError = function($connection, $code, $msg){};
// 当连接远程websocket服务器的连接断开时// 如果连接断开20秒后自动重连
$conC->onClose = function($connection){print_r(date('Y-m-d H:i:s',time())." 重连"); $connection->reconnect(5);};
$conC->connect();
};
Worker::runAll();

类似这样,可以实现吗?:

use app\date\model\SystemNode;
SystemNode::mk()->where($map)->update();

我引用了之后报错:

 Error: Call to a member function connect() on null in F:\okx\tp\vendor\topthink\think-orm\src\Model.php:357
Stack trace:
#0 F:\okx\tp\vendor\topthink\think-orm\src\Model.php(1045): think\Model->db()
#1 F:\okx\tp\vendor\zoujingli\think-library\src\Model.php(96): think\Model- >__call('where', Array)
#2 F:\okx\tp\Startws3.php(53): think\admin\Model->__call('where', Array)
#3 F:\okx\tp\vendor\workerman\workerman\Connection\AsyncTcpConnection.php(345): Startws3\{closure}(Object(Workerman\Connection\AsyncTcpConnection))
#4 F:\okx\tp\vendor\workerman\workerman\Events\Select.php(302): Workerman\Connection\AsyncTcpConnection->checkConnection(Resource id #27)
#5 F:\okx\tp\vendor\workerman\workerman\Worker.php(2410): Workerman\Events\Select->loop()
#6 F:\okx\tp\vendor\workerman\workerman\Worker.php(1406): Workerman\Worker->run()
#7 F:\okx\tp\vendor\workerman\workerman\Worker.php(1349): Workerman\Worker::forkWorkersForWindows()
#8 F:\okx\tp\vendor\workerman\workerman\Worker.php(546): Workerman\Worker::forkWorkers()
#9 F:\okx\tp\Startws3.php(180): Workerman\Worker::runAll()
#10 {main}
Worker process terminated
670 3 0
3个回答

nitron

不能,需要自行连接数据库

CC.

表太多了,都是用tp6的数据库操作,一下子换workerman换不过来

  • 暂无评论
CC.

tp6指令 liunx下不支持AsyncTcpConnection

  • 暂无评论
年代过于久远,无法发表回答
🔝