要使用PHP STOMP发送消息,您需要首先安装一个名为stomp.php的库。您可以使用Composer来安装它:
composer require cboden/stomp然后,您可以使用以下示例代码发送STOMP消息:
<?phprequire_once 'vendor/autoload.php';use Stomp\Client;// STOMP服务器的连接信息$host = 'localhost';$port = 61613;$username = 'your_username';$password = 'your_password';// 创建一个Stomp客户端实例$client = new Client("tcp://{$host}:{$port}", $username, $password);// 连接到STOMP服务器$client->connect();// 要发送的消息$message = 'Hello, STOMP!';// 将消息发送到指定的队列或主题$client->send("/queue/your_queue", '', $message);// 断开与STOMP服务器的连接$client->disconnect();echo "Message sent: {$message}\n";?>请确保将your_username,your_password和your_queue替换为您的STOMP服务器的实际值。此代码将连接到STOMP服务器,发送一条消息到指定的队列,然后断开连接。


