测试异步

This commit is contained in:
2025-12-03 10:28:05 +08:00
parent 05db9b6f02
commit a92b5d85f6
2 changed files with 19 additions and 1 deletions

View File

@@ -877,6 +877,7 @@ class Ceshi extends Controllers
} else {
// 子进程
sleep(5);
Log::record("子进程5秒后执行".json_encode($pid),"infoss");
echo "子进程5秒后执行\n";
exit(0); // 子进程结束
}

View File

@@ -5,6 +5,7 @@ namespace app\api\model;
use app\common\controller\Push;
use think\Cache;
use think\Db;
use think\Log;
use think\Model;
class Room extends Model
@@ -886,7 +887,23 @@ class Room extends Model
$ttex['FromUserInfo'] = db::name('user')->where('id', $user_id)->field('id as user_id,nickname,avatar,sex')->find();
$ttex['ToUserInfo'] = db::name('user')->where('id', $partner_id)->field('id as user_id,nickname,avatar,sex')->find();
$ttex['text'] = 'CP特效';
model('api/Chat')->sendMsg(1080, $room_id, $ttex);
// 子进程推送CP特效消息
$pid = pcntl_fork();
if ($pid == -1) {
// 创建子进程失败,直接推送消息
model('api/Chat')->sendMsg(1080, $room_id, $ttex);
} elseif ($pid) {
// 父进程,继续执行
// 不等待子进程结束
} else {
// 子进程,延迟推送消息
sleep(1);
model('api/Chat')->sendMsg(1080, $room_id, $ttex);
exit(0); // 子进程结束
}
}
}
}