swoole提示must be called in the coroutine解决办法
报错信息:
解决方法:
PHP Code复制内容到剪贴板
- function getOneHjjcData(){
- global $MAXID;
- go(function() use ($MAXID){
- echo $MAXID."\n";
- $swoole_mysql = new Swoole\Coroutine\MySQL();
- $swoole_mysql->connect([
- 'host' => MYSQL_HOST,
- 'port' => MYSQL_PORT,
- 'user' => MYSQL_USER,
- 'password' => MYSQL_PASSWORD,
- 'database' => MYSQL_DATABASE,
- ]);
- // 传输设备号是26的给联通
- $sql = "select * from widom_sb_hjjc_data where id > {$MAXID} and sb_id=26";
- $res = $swoole_mysql->query($sql);
- if($res){
- $MAXID = $res["id"];
- }
- echo $MAXID."\n";
- print_r($res);
- });
- }
- getOneHjjcData();
最重要的一行:
PHP Code复制内容到剪贴板
- go(function() {
- $db = new Swoole\Coroutine\MySQL();
- });
把代码放到协程中去就行了