您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman常用组件-MySQL组件-workerman之使用Workerman-MySQL - 具体MySQL的Connection用法-事務
发布时间:2021-12-22 23:19:52编辑:雪饮阅读()
實例哥:
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onWorkerStart = function($worker)
{
global $db;
// 初始化db连接
$db = new \Workerman\MySQL\Connection('127.0.0.1', '3306', 'xy', 'xy', 'workerman');
};
$worker->onMessage = function(TcpConnection $connection, $data)
{
global $db;
$db->beginTrans();
$db->delete('phome_ecms_news')->where('ID=84')->query();
$db->query("DELETE FROM `phome_ecms_news` WHERE ID=85");
$res=$db->rollBackTrans();
$db->beginTrans();
$db->delete('phome_ecms_news')->where('ID=84')->query();
$db->query("DELETE FROM `phome_ecms_news` WHERE ID=85");
$res=$db->commitTrans();
$response["res"]=$res;
$connection->send(json_encode($response));
};
Worker::runAll();
運行哥:
[root@localhost www.fpm.com]# /usr/local/php734/bin/php channelServer.php start
Workerman[channelServer.php] start in DEBUG mode
------------------------------------------- WORKERMAN --------------------------------------------
Workerman version:4.0.22 PHP version:7.3.4
-------------------------------------------- WORKERS ---------------------------------------------
proto user worker listen processes status
tcp root none websocket://0.0.0.0:8484 1 [OK]
--------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
有客戶端訪問並觸發了上面服務實例中的onMessage事件時並部署了sql追蹤器時如:
2021-12-22T15:17:48.856530Z 9 Query START TRANSACTION
2021-12-22T15:17:48.857108Z 9 Prepare DELETE FROM `phome_ecms_news` WHERE ID=84
2021-12-22T15:17:48.857238Z 9 Execute DELETE FROM `phome_ecms_news` WHERE ID=84
2021-12-22T15:17:48.857768Z 9 Prepare DELETE FROM `phome_ecms_news` WHERE ID=85
2021-12-22T15:17:48.857917Z 9 Close stmt
2021-12-22T15:17:48.857943Z 9 Execute DELETE FROM `phome_ecms_news` WHERE ID=85
2021-12-22T15:17:48.858376Z 9 Query ROLLBACK
2021-12-22T15:17:48.860878Z 9 Query START TRANSACTION
2021-12-22T15:17:48.861427Z 9 Prepare DELETE FROM `phome_ecms_news` WHERE ID=84
2021-12-22T15:17:48.861662Z 9 Close stmt
2021-12-22T15:17:48.861690Z 9 Execute DELETE FROM `phome_ecms_news` WHERE ID=84
2021-12-22T15:17:48.862002Z 9 Prepare DELETE FROM `phome_ecms_news` WHERE ID=85
2021-12-22T15:17:48.862120Z 9 Close stmt
2021-12-22T15:17:48.862139Z 9 Execute DELETE FROM `phome_ecms_news` WHERE ID=85
2021-12-22T15:17:48.862345Z 9 Query COMMIT
2021-12-22T15:17:48.863641Z 9 Query START TRANSACTION
2021-12-22T15:17:48.863890Z 9 Prepare DELETE FROM `phome_ecms_news` WHERE ID=84
2021-12-22T15:17:48.864108Z 9 Close stmt
2021-12-22T15:17:48.864139Z 9 Execute DELETE FROM `phome_ecms_news` WHERE ID=84
2021-12-22T15:17:48.864635Z 9 Prepare DELETE FROM `phome_ecms_news` WHERE ID=85
2021-12-22T15:17:48.864783Z 9 Close stmt
2021-12-22T15:17:48.864858Z 9 Execute DELETE FROM `phome_ecms_news` WHERE ID=85
2021-12-22T15:17:48.865082Z 9 Query ROLLBACK
2021-12-22T15:17:48.865193Z 9 Query START TRANSACTION
2021-12-22T15:17:48.865386Z 9 Prepare DELETE FROM `phome_ecms_news` WHERE ID=84
2021-12-22T15:17:48.865507Z 9 Close stmt
2021-12-22T15:17:48.865570Z 9 Execute DELETE FROM `phome_ecms_news` WHERE ID=84
2021-12-22T15:17:48.865751Z 9 Prepare DELETE FROM `phome_ecms_news` WHERE ID=85
2021-12-22T15:17:48.865857Z 9 Close stmt
2021-12-22T15:17:48.865876Z 9 Execute DELETE FROM `phome_ecms_news` WHERE ID=85
2021-12-22T15:17:48.866057Z 9 Query COMMIT
关键字词:workerman,组件,Connection,事務,MySQL
相关文章
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之安装 Worker