📄 sam.examples.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Examples</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sam.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="sam.messages.html">Messages</a></div> <div class="up"><a href="book.sam.html">SAM</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1>Examples</h1><h2>Table of Contents</h2><ul class="chunklist chunklist_chapter"><li><a href="sam.messages.html">Messages</a></li><li><a href="sam.operations.html">Messaging operations</a></li><li><a href="sam.pubsub.html">Publish/Subscribe and suscriptions to topics</a></li><li><a href="sam.errors.html">Error handling</a></li></ul> <div id="sam.connections" class="section"> <h2 class="title">Connections</h2> <p class="para"> In order to perform any messaging and queueing functions a connection must be established with a messaging server by creating a SAMConnection object and calling its "connect" method, with a set of connection properties, to connect the PHP script to the messaging server. Until such time as the SAMConnection object is destroyed the connection will be maintained and available for use. All SAMConnection objects are destroyed when the PHP script exits. </p> <p class="para"> A set of default properties may be used in connecting to a messaging server but as a minimum the PHP script must specify a protocol to be used. </p> <p class="para"> <div class="example"> <p><b>Example #1 Creating a connection and connecting to a remote WebSphere MQSeries Messaging Server</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$conn </span><span style="color: #007700">= new </span><span style="color: #0000BB">SAMConnection</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #0000BB">SAM_WMQ</span><span style="color: #007700">, array(</span><span style="color: #0000BB">SAM_HOST </span><span style="color: #007700">=> </span><span style="color: #DD0000">'myhost.mycompany.com'</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">SAM_PORT </span><span style="color: #007700">=> </span><span style="color: #0000BB">1506</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">SAM_BROKER </span><span style="color: #007700">=> </span><span style="color: #DD0000">'mybroker'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #2 Creating a connection and connecting to a remote WebSphere Application Server</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$conn </span><span style="color: #007700">= new </span><span style="color: #0000BB">SAMConnection</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #0000BB">SAM_WPM</span><span style="color: #007700">, array(</span><span style="color: #0000BB">SAM_ENDPOINTS </span><span style="color: #007700">=> </span><span style="color: #DD0000">'localhost:7278:BootstrapBasicMessaging'</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">SAM_BUS </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Bus1'</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">SAM_TARGETCHAIN </span><span style="color: #007700">=> </span><span style="color: #DD0000">'InboundBasicMessaging'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #3 Creating a connection and connecting to an MQTT server</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$conn </span><span style="color: #007700">= new </span><span style="color: #0000BB">SAMConnection</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #0000BB">SAM_MQTT</span><span style="color: #007700">, array(</span><span style="color: #0000BB">SAM_HOST </span><span style="color: #007700">=> </span><span style="color: #DD0000">'myhost.mycompany.com'</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">SAM_PORT </span><span style="color: #007700">=> </span><span style="color: #0000BB">1883</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sam.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="sam.messages.html">Messages</a></div> <div class="up"><a href="book.sam.html">SAM</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -