|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-01-25 13:05 UTC] markright at gmail dot com
Description:
------------
When using SAM to send a message via MQTT a number of notices are thrown.
Notice: Use of undefined constant SAM_PORT - assumed 'SAM_PORT' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 102
Notice: Use of undefined constant SAM_PORT - assumed 'SAM_PORT' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 105
Notice: Use of undefined constant SAM_HOST - assumed 'SAM_HOST' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 107
Notice: Use of undefined constant SAM_HOST - assumed 'SAM_HOST' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 110
Notice: Use of undefined constant SAM_WAIT - assumed 'SAM_WAIT' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 237
Notice: Undefined index: SAM_WAIT in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 237
Reproduce code:
---------------
<?php
include_once('/usr/share/php/SAM/php_sam.php');
$conn = new SAMConnection();
$conn->setdebug(TRUE);
$conn->connect(SAM_MQTT, array(SAM_HOST => 'localhost',SAM_PORT => 1883));
$subName = $conn->subscribe('topic://send/test');
if (!$subName) {
echo "Subscribe failed";
} else {
}
$msg = new SAMMessage('This is a simple text message');
$msg->header->SAM_REPLY_TO = 'topic://receive/test';
$correlid = $conn->send('topic://send/test', $msg);
if (!$correlid) {
echo "Send failed ($conn->errno) $conn->error";
} else {
$resp = $conn->receive($subName, array(SAM_CORRELID => $correlid));
}
echo $resp->body;
?>
Expected result:
----------------
This is a simple text message
Actual result:
--------------
Notice: Use of undefined constant SAM_PORT - assumed 'SAM_PORT' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 102
Notice: Use of undefined constant SAM_PORT - assumed 'SAM_PORT' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 105
Notice: Use of undefined constant SAM_HOST - assumed 'SAM_HOST' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 107
Notice: Use of undefined constant SAM_HOST - assumed 'SAM_HOST' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 110
Notice: Use of undefined constant SAM_WAIT - assumed 'SAM_WAIT' in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 237
Notice: Undefined index: SAM_WAIT in /usr/share/pear/SAM/MQTT/sam_mqtt.php on line 237
This is a simple text message
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 09:00:01 2025 UTC |
Here is a patch which fixes these notices Index: sam/MQTT/sam_mqtt.php =================================================================== RCS file: /repository/pecl/sam/MQTT/sam_mqtt.php,v retrieving revision 1.1 diff -u -u -r1.1 sam_mqtt.php --- sam/MQTT/sam_mqtt.php 2 Feb 2007 15:36:46 -0000 1.1 +++ sam/MQTT/sam_mqtt.php 25 Jan 2009 18:32:10 -0000 @@ -99,15 +99,15 @@ if ($this->debug) e('SAMConnection_MQTT.Connect()'); /* Check our optional parameter array for the necessary bits... */ - if ($options[SAM_PORT] == '') { + if ($options['SAM_PORT'] == '') { $this->port = 1883; } else { - $this->port = $options[SAM_PORT]; + $this->port = $options['SAM_PORT']; } - if ($options[SAM_HOST] == '') { + if ($options['SAM_HOST'] == '') { $this->host = 'localhost'; } else { - $this->host = $options[SAM_HOST]; + $this->host = $options['SAM_HOST']; } $this->cleanstart = in_array(SAM_MQTT_CLEANSTART, $options); @@ -234,10 +234,10 @@ if ($rc) { /* have we got a timeout specified? */ - if ($options[SAM_WAIT] > 1) { - $m = $options[SAM_WAIT] % 1000; - $s = ($options[SAM_WAIT] - $m) /1000; - if ($this->debug) t('SAMConnection_MQTT.Receive() timeout='.$options[SAM_WAIT]." ($s secs $m millisecs)"); + if (isset($options['SAM_WAIT']) && $options['SAM_WAIT'] > 1) { + $m = $options['SAM_WAIT'] % 1000; + $s = ($options['SAM_WAIT'] - $m) /1000; + if ($this->debug) t('SAMConnection_MQTT.Receive() timeout='.$options['SAM_WAIT']." ($s secs $m millisecs)"); stream_set_timeout($this->sock, $s, $m); if ($this->debug) t('SAMConnection_MQTT.Receive() timeout set.'); } else {