dongzhijing8202 2011-11-01 21:00
浏览 66

使用PHP / Linux连接到MQ

Is there anyone out there who successfully is using PHP/Linux to connect to MQ? For days I have desperately been trying to get this to work but to no avail. IF there's anyone out there who is doing this, how?

As I see it there's two extensions to use: a) mqseries -> a thin wrapper to the C API b) SAM 1.1.0 -> taking a more general approach

I've tried both but for a) I am able to do MQCONNX successfully, but not MQOPEN and for b) I am not getting past the MQCONN stage. I've tried both the 7 and the 6 Client. Our server is running 6.0.0.0.

Note; we've successfully been connecting to the server using .NET for years.

So this is what I've done so far:

  1. Installed the MQClient from RPM packages
  2. Installed IA94/XMS
  3. Succesfully built the sam_xms.so extension and included that in my php.ini
  4. Successfulyl built mqseries.so extension and included that as well.
  5. Successfully been running the Samples from the mq client installation (amqsputc and amqsgetc) and been passing messages back and forth.

Using the mqseries PECL extension this is the error I get:

MQOPEN failed; CompCode:2 Reason:2044 Text:2044

Using the SAM PECL extension I get this instead:

<--SAMConnection.SetDebug()
-->SAMConnection.Connect()
-->SAMConnection.Create(proto=wmq:client)
   SAMConnection.Create() get_cfg_var() ""
   SAMConnection.Create() calling factory - SAM/sam_factory_xms.php
   SAMConnection.Create() rc = SAMXMSConnection
<--SAMConnection.Create()
   SAMConnection.Connect() connection created for protocol wmq:client
   SAMConnection.Connect() connect failed (208) Unable to create XMS connection!
<--SAMConnection.Connect() rc=
-->SAMConnection.IsConnected()
   SAMConnection.IsConnected() isconnected failed (208) Unable to create XMS connection!
<--SAMConnection.IsConnected() rc=
Connection failed (208) Unable to create XMS connection!

Neither of these errors generates anything in /var/mqm/errors...

Here's my sample code for mqseries:

mqseries_conn('MQED', $conn, $comp_code, $reason);
if ($comp_code !== MQSERIES_MQCC_OK) {
    printf("<br>MQCONNX failed; Connx CompCode:%d Reason:%d Text:%s<br>
", $comp_code, $reason, $reason);
    exit;
}
else
{
    printf("<br>MQCONNX successful: Connx CompCode:%d Reason:%d Text:%s<br>
<br>", $comp_code, $reason, $reason);
}

$mqods = array('ObjectName'=>'MYPUTQUEUE');
mqseries_open($conn, $mqods, 
          MQSERIES_MQOO_INPUT_AS_Q_DEF | MQSERIES_MQOO_FAIL_IF_QUIESCING | MQSERIES_MQOO_OUTPUT,
          $obj, $comp_code,$reason);

if ($comp_code !== MQSERIES_MQCC_OK) {
printf("<br><br>MQOPEN failed; CompCode:%d Reason:%d Text:%s<br><br>", 
        $comp_code, 
        $reason, 
        $reason);
}
else
{
printf("<br><br>MQOPEN successful; CompCode:%d Reason:%d Text:%s<br><br>", 
        $comp_code, 
        $reason, 
        $reason);
}

Here's the sample code using the SAM extension:

$conn->connect(SAM_WMQ_CLIENT, array(SAM_BROKER => 'MQED',SAM_TRANSACTIONS => SAM_MANUAL));

if($conn->isConnected())
{
    $msg = new SAMMessage('MY MESSAGE');

    $msg->header->SAM_REPLY_TO = 'MYGETQUEUE';
    $correlid = $conn->send('MYPUTQUEUE', $msg);

    if (!$correlid) {
    // The Send failed!
        echo "Send failed ($conn->errno) $conn->error";
    } else {
        $resp = $conn->receive('MYGETQUEUE', array(SAM_CORRELID => $correlid));
    }

    $conn->disconnect();
}
else
{
    echo "Connection failed ($conn->errno) $conn->error";
}

Thank you everyone in advance!

Note, this is a continuation of the discussion on Trying to connect to MQ using PHP; almost there

Update #1: MQPUT1 works, but MQOPEN is still returning 2044.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值