我正在尝试从 PHP(版本 7)向 Microsoft 消息队列 (MSMQ) 发送消息。
任何人都可以向我提供代码示例或向我指出可用于使用 PHP 向 MSMQ 发送消息的相关文档或库吗?
任何帮助或指导将不胜感激。预先感谢您!
我已经解决了它,这是可以用于此类问题的解决方案。
<?php
define("MQ_SEND_ACCESS", 2);
define("MQ_DENY_NONE", 0);
try {
$msgQueueInfo = new COM("MSMQ.MSMQQueueInfo");
$msgQueueInfo->PathName = ".\\private$\\messages";
$msgQueue = $msgQueueInfo->Open(MQ_SEND_ACCESS, MQ_DENY_NONE);
if (!$msgQueue) {
throw new Exception("Failed to open the queue.");
}
$msgOut = new COM("MSMQ.MSMQMessage");
$msgOut->Body = "It's my first commit";
$msgOut->Send($msgQueue);
$msgQueue->Close();
unset($msgOut);
unset($msgQueue);
unset($msgQueueInfo);
echo "Message sent successfully.";
} catch (Exception $e) {
echo "An error occurred: " . $e->getMessage();
}
?>