Swoole_MQ.php如何实现高效长尾词消息队列管理?

2026-04-03 04:471阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计194个文字,预计阅读时间需要1分钟。

Swoole_MQ.php如何实现高效长尾词消息队列管理?

phpserv->set([ 'worker_num'=> 8, 'max_conn'=> 1000, 'max_request'=> 100000, 'debug_mode'=> 1, 'task_worker_num'=> 8, 'daemonize'=> true]);?>

swoole_mq.php

serv = new swoole_localhost:61613"); #$con->subscribe($topic); $serv->mq['conn']->subscribe($queue); $msg = "test".time(); #$con->send($topic, $msg); $serv->mq['conn']->send($queue, $msg); echo "Sent message with body '".$msg."'\n"; } catch(StompException $e) { die('Connection failed: ' . $e->getMessage()); } /* read a frame */ while(true) { $frame = $serv->mq['conn']->readFrame(); $db = new mysqli('127.0.0.1', 'ymshop', 'xxxxxx', 'shop_seo'); $stmt = $db->prepare("show tables"); var_dump($stmt); if ($frame != null) { echo $frame->body; /* acknowledge that the frame was received */ $serv->mq['conn']->ack($frame); } }//while } } public function onReceive(swoole_server $serv, $fd, $from_id, $data){ $serv->task(""); } public function onClose( $serv, $fd, $from_id ) { echo "Client {$fd} close connection\n"; } public function onTask($serv,$task_id,$from_id, $data) { //send msg to rabbitmq $serv->mq['exchange']->publish($data,$this->mq_queue_name); } public function onFinish($serv,$task_id, $data) { } } new server();

Swoole_MQ.php如何实现高效长尾词消息队列管理?
标签:Swoolemqphpse

本文共计194个文字,预计阅读时间需要1分钟。

Swoole_MQ.php如何实现高效长尾词消息队列管理?

phpserv->set([ 'worker_num'=> 8, 'max_conn'=> 1000, 'max_request'=> 100000, 'debug_mode'=> 1, 'task_worker_num'=> 8, 'daemonize'=> true]);?>

swoole_mq.php

serv = new swoole_localhost:61613"); #$con->subscribe($topic); $serv->mq['conn']->subscribe($queue); $msg = "test".time(); #$con->send($topic, $msg); $serv->mq['conn']->send($queue, $msg); echo "Sent message with body '".$msg."'\n"; } catch(StompException $e) { die('Connection failed: ' . $e->getMessage()); } /* read a frame */ while(true) { $frame = $serv->mq['conn']->readFrame(); $db = new mysqli('127.0.0.1', 'ymshop', 'xxxxxx', 'shop_seo'); $stmt = $db->prepare("show tables"); var_dump($stmt); if ($frame != null) { echo $frame->body; /* acknowledge that the frame was received */ $serv->mq['conn']->ack($frame); } }//while } } public function onReceive(swoole_server $serv, $fd, $from_id, $data){ $serv->task(""); } public function onClose( $serv, $fd, $from_id ) { echo "Client {$fd} close connection\n"; } public function onTask($serv,$task_id,$from_id, $data) { //send msg to rabbitmq $serv->mq['exchange']->publish($data,$this->mq_queue_name); } public function onFinish($serv,$task_id, $data) { } } new server();

Swoole_MQ.php如何实现高效长尾词消息队列管理?
标签:Swoolemqphpse