Hướng dẫn dùng mq series trong PHP
MQ provides support for a number of programming languages, for example C, COBOL and Java. The full list is documented in the MQ Knowledge Centre here: Show https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q022830_.htm IBM does not provide a PHP API for MQ. There is a PHP Extension Community Library (PECL) package for that provides a PHP wrapper to the MQ C libraries. Again it must be stressed that IBM does not provide support for this extension. Running PHP MQ ExamplesThis document describes how to get the put and get example PHP programs supplied with the PHP MQ extension working with the PHP MQ package being downloaded from: http://pecl.php.net/package/mqseries Using the instructions found here: https://blog.phpdeveloper.org/2009/07/29/mqphp-linking-ibms-websphere-mq-to-php/ These steps were carried out on RHEL 6.8 using MQ V8.0 which was already installed but at /opt/mqm80 rather than the default of /opt/mqm we also had the MQClient package installed. Preliminary setup on LinuxWe installed the Linux PHP packages and the required dependencies Installed PHP-dev package and dependencies to get the phpize command and downloaded the MQSeries extension from: http://pecl.php.net/package/mqseries We used version 0.14.2. Build the MQSeries extension libraryThe next step was to build the PHP MQSeries library which involved the following commands: phpize Which ran OK with little output then: ./configure --with-libdir=lib64 This ran OK when we updated the configure script to add /opt/mqm80 to the SEARCH_PATH= variable on line 4169. Then we ran: make Which ran OK and created mqseries_helper.lo mqseries.lo and mqseries.la in /home/gb036159/0PJB/temp/mqseries-0.14.2/mqseries-0.14.2. We found mqseries.so in: ./home/gb036159/0PJB/temp/mqseries-0.14.2/mqseries-0.14.2/.libs/mqseries.so Next to check the location of the PHP extensions directory we ran: php -i | grep extension_dir Which showed the php extension dir to be: extension_dir => /usr/lib64/php/modules => /usr/lib64/php/modules We then copied mqseries.so to /usr/lib64/php/modules from /home/gb036159/0PJB/temp/mqseries-0.14.2/mqseries-0.14.2/modules using the command: sudo cp mqseries.so /usr/lib64/php/modules/mqseries.so Finally used the php -m command to confirm that the MQSeries extension has been installed. Run a simple PHP MQ program to connect to the queue managerThe instructions linked to above provide a sample PHP program that connects to a queue manager the PHP code is: #!/usr/bin/php -q This sample was modified to suit our local MQ setup the name of our queue manager was IB10QMGR and the channel name was IB10QMGR.SVRCONN. This sample program only connects to the queue manager using MQ client - it doesn't attempt to put or get any messages. We saved this PHP script as php_mq_test and then ran it: [gb036159@oc6834500546 PHP-MQ]$ ./php_mq_test.php When we stopped the queue manager IB10QMGR and re-ran the test PHP script we saw the following output: [gb036159@oc6834500546 PHP-MQ]$ ./php_mq_test.php Run the put.php and get.php examplesIn the extracted MQSeries PHP package there is an Examples sub-directory which contains a number of PHP MQ samples. We used the put.php and get.php samples. Both of these were modified to change the name of the queue manager to IB10QMGR and the MQ client channel name to IB10QMGR.SVRCONN also the MQ queue name was changed to QL_PHP_TEST. We ran put.php three times: [gb036159@oc6834500546 PHP-MQ]$ ./put.php Then we checked the depth of the QL_PHP_TEST: gb036159@oc6834500546 PHP-MQ]$ echo "dis
ql(QL_PHP_TEST) CURDEPTH" | runmqsc IB10QMGR 1 : dis ql(QL_PHP_TEST) CURDEPTH Next we ran get.php to get the messages from the queue we ran this program four times: [gb036159@oc6834500546 PHP-MQ]$ ./get.php The fourth run resulted in the MQ reason code 2033 No message available - which is expected because we put three messages to the queue. |