Within the socket service, how do I invoke symfony's doctrine service to operate the database?

how do I invoke symfony"s doctrine service to operate the database within a socket service?

php website project done with symfony framework needs to use websocket service. The service written by socketio is started on the command line. Now it needs to query and save database operation in socket service. How should it be implemented?

the server program is as follows:

use Workerman\Worker;
use Workerman\WebServer;
use Workerman\Autoloader;
use PHPSocketIO\SocketIO;
require_once dirname(__DIR__,2)."/vendor/autoload.php";

$io = new SocketIO(2021);
$io->on("connection", function($socket) use($io) {
    $socket->addedUser = false;
    $socket->roleType = "";
    var_dump("connection");
    
    $socket->on("message", function($data) use($socket, $io) {
        var_dump($data);
        //

    });

    // 
    $socket->on("disconnect", function () use($socket, $io, $entityManager) {
        var_dump("disconnect");
    });
});

if (!defined("GLOBAL_START")) {
    Worker::runAll();
}

Jul.06,2022

you can use PDO directly. Pass parameters in the closure

$pdo = new PDO("mysql:host=xxxxxxx;dbname=test", "username", "password123");
$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$socket->on("message", function($data) use($socket, $io,$pdo) {
        var_dump($data);
        //
        $rows = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);

    });
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bc08a6-2fd5d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bc08a6-2fd5d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?