1

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>\n", $comp_code, $reason, $reason);
    exit;
}
else
{
    printf("<br>MQCONNX successful: Connx CompCode:%d Reason:%d Text:%s<br>\n<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.

Community
  • 1
  • 1
eriben
  • 188
  • 10

0 Answers0