为方便测试,如果没有mysql的建议使用rand(min, max)测试。
测试代码:
//刷队列,取数据 while (true) { $msg = code(trim(rand(2, 60))); var_dump(trim($msg)); sleep(5); socket_write($msgsock, $msg, strlen($msg)); }
数据库版
//连接数据库 $dsn = 'mysql:dbname=v2qiaodu;host=localhost'; $user = 'root'; $pass = 'root'; $pdo = new PDO($dsn, $user, $pass);
循环读取数据库数据
//循环读取数据库数据; while (true) { /*总记录数*/ $sql = "select orders_id,orders_price from po_orders LIMIT 10"; $stmt = $pdo->query($sql); $data = $stmt->fetchAll(); $res['data'] = $data; $val = json_encode($res); //$val = rand(2, 60); $msg = code(trim($val)); var_dump(trim($msg)); sleep(5); socket_write($msgsock, $msg, strlen($msg)); }
Done!