MQ+PHP – Linking IBM’s WebSphere MQ to PHP

During a recent project at work I had to get PHP linked with IBM’s WebSPhere MQ software we have running on another internal server. Our goal was to use our existing web service to take the requests from external vendors and push their XML data back into the queue inside our firewall. Thankfully there’s an extension in PECL that does just that.

Here’s the basic steps I took – hopefully it’ll be useful to someone else out there in the same spot I was. This all assumes you’re working on a web server that doesn’t have an MQ server installed already:

  • Get the extension: Head over to the PECL page for mqseries and download the latest version. Unpack it into a directory on your local server
  • Get the MQ client libs: You’ll need to go to IBM’s website to download the latest client/libraries for your install (you’ll need an IBM ID to get to the downloads):
    • Go to the IBM page for the MQ client listing
    • Look for the “WebSphere MQ Clients” link under the “Related products and technologies” section and click on it
    • Scroll down to the “Download Package” section and choose from one of the mirror locations
    • Select your package from the list (I went with “Linux for System x86″ for our setup)
    • Click on the download link and fill out some required information (you didn’t think you were getting off that easy, did you?)
    • Agree to the terms and conditions and you’ll get a “Download Now” link
    • Drop the archive file (tar, tar.gz, etc) into your server and unpack into a temporary directory (mine had an issue unpacking into the local directory, not a subdirectory)
  • Install the package(s): Once you have the IBM software extracted, you should have a series of packages. You’ll need to install the “MQSeriesSDK” to get the right libraries in place to compile the PHP extension
  • Build the mqseries extension: Go into the mqseries directory and run “phpize”, “./configure” and “make” to create the .so file. The process should drop it into the default extensions directory.
  • If needed, move it: Be sure that the shared module for the extension is in the right directory for the PHP install to find it. (You can make a phpinfo() page if you’re not sure where that is.)
  • Update your php.ini: Add in a line to include the extension in your current setup. Remember, after any changes to the php.ini, you need to restart the web server.

Now for the fun part – if everything’s working and the extension shows up in your phpinfo() as active, give this script a shot and see if you can connect to your MQ server:

$mq_host_ip         ='127.0.0.1';
$queue_name     = 'HOST.REMOTE.Q';
$mq_server      = 'WBRK_QM_U49';
$mqcno = array(
        'Version' => MQSERIES_MQCNO_VERSION_2,
        'Options' => MQSERIES_MQCNO_STANDARD_BINDING,
        'MQCD' => array(
                'ChannelName'                   => 'CLIENT.CHANNEL',
                'ConnectionName'                => $mq_host_ip,
                'TransportType'                 => MQSERIES_MQXPT_TCP
        )
);

// Connect to the MQ server
mqseries_connx($mq_server,$mqcno,$conn,$comp_code,$reason);
if ($comp_code !== MQSERIES_MQCC_OK) {
        trigger_error('Cannot open connection to server: '.$mq_server,E_USER_ERROR);
}else{
      echo 'Connection good!';
}

Obviously you’ll need to adjust the settings to fit your server, but at least this gives you a start.

Category: Deployment, PHP 7 comments »

7 Responses to “MQ+PHP – Linking IBM’s WebSphere MQ to PHP”

  1. Chris

    Hi,

    i also try to connect to a mq server. Found this post as i search for other examples for mqseries options as there is not really much documentation and nothing else usabele out there.
    First, with the MA01 Support Pack and the “q” command line tool, i can connect to the server and also send and get messages. But not with php and mqseries. I also tried the mqseries_connx method, but alwas got Error Code 2059, which meens QMgr is not available (mqseries_strerror does not really work, but this is the MQ Errorcode for it).
    What i miss in the config you and i use is the port. Have you any idea how to set the port in the options array?
    I contacted the author of the package, but with no response.

    Chris

  2. Chris

    If anyone other have the same problem, using a different port, you simply could use: $mq_host_ip =’127.0.0.1(PORT)’; Where PORT ist your Port.

  3. enygma

    @chris excellent! Glad you figured it out, hopefully this tip will help out more of the few PHPers having to deal with the MQ stuff

  4. Chris

    No Problem. But now i have another problem, with the mqseries_open function. Using the code from the mqseries exaples it says: $mqods = array(‘ObjectName’ => ‘TESTQ’, ‘ObjectQMgrName’ => ‘MQNX9420′);. Where ObjectName seems to be the name of the queue und ObjectQMgrName the name of the queue manager used in mqseries_connx. But if i use these options i get error 2085 – MQRC_UNKNOWN_OBJECT_NAME (see http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=/com.ibm.mq.amqzao.doc/fm12810_.htm). I dont know what to do. spend the half night with it and tried everything. Do you have an idea?

  5. Luis

    Has anybody compiled this MQ package for Windows? I would love to use it, but I can’t compile it.

    Thanks.

  6. Arun

    can any one please provide a php_mqseries.dll

  7. Bhaskar

    Hi,

    Thanks for the post. I was able to connect to WebSphereMQ and send and receive messages from Linux.

    Is there any way to pass a username to the MQ server with the request? The MQ server I am using allows controls access by username and the only way I have been able to get this working is by changing the apache profile name to whatever username has access on the MQ.

    Also, the download link for the MQ libraries didn’t work, and I was able to download them from https://www14.software.ibm.com/webapp/iwm/web/download.do?source=swg-iwmqv60211c&S_PKG=dl1&S_TACT=WMQ&lang=en_US&dlmethod=http.


Leave a Reply



Back to top