adding groupname alias through php script creates problem
When I am adding aliases through php script, don’t know why, but the socket is not getting closed, due to which the script stays in execution mode only.
The alias gets added through the script, but the problem is that the php script remains in execution mode, may be socket doesn’t close.
For achieving this functionality, I used two php files:
1. script_execute_telnet_command.php
2. script_add_alias.php
Content of first file(script_execute_telnet_command.php) is as below:
<?php
function execute_telnet_function($telnet_command)
{
error_reporting(E_ALL);
//echo "<h2>TCP/IP Connection</h2>n";
/* Get the port for the WWW service. */
//$service_port = getservbyname(‘www’, ‘tcp’);
$service_port = 1112;
/* Get the IP address for the target host. */
//$address = gethostbyname(‘www.ecosmob.com’);
$address = "127.0.0.1";
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "n";
} else {
//echo "OK.n";
}
//echo "Attempting to connect to ‘$address’ on port ‘$service_port’…";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "socket_connect() failed.nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "n";
} else {
//echo "OK.n";
}
$out = ”;
//echo "Sending HTTP HEAD request…";
//socket_write($socket, $in, strlen($in));
socket_write($socket, $telnet_command, strlen($telnet_command));
//echo "OK.n";
$returnout="";
//echo "Reading response:nn";
while ($out = socket_read($socket, 2048)) {
$returnout .= $out;
}
//echo $returnout;
//echo "Closing socket…";
socket_close($socket);
//echo "OK.nn";
return $returnout;
}
?>
Content of second file(script_add_alias.php) is as below:
<?php
include_once("script_execute_telnet_command.php");
$response="";
$add_alias_command="";
$add_alias_command.="addgroupnamealias groupname=STREAM_NAME_GROUPNAME aliasname=testrn";
$response = execute_telnet_function($add_alias_command);
echo "response starts : n";
print_r($response);
echo "nresponse endsnn";
?>
From Above code, streamname alias gets added, but scripts keeps on running mode.
I know, I haven’t added "quit" command in second script after below line:
$add_alias_command.="addgroupnamealias groupname=STREAM_NAME_GROUPNAME aliasname=testrn";
But that is done intentionally.
As I add "quit" command line, after "addgroupnamealias" command as below
$add_alias_command.="quitrn";
in the script,
the script gets closed, and even the alias didn’t get added.
————————————————————————————————————————————————
When I execute the same commands in telnet manually, there’s a special character, that gets added in every command’s output, except "addgroupnamealias" command, is it related to that?
Command in telnet :
1.
addgroupnamealias groupname=STREAM_NAME_GROUPNAME aliasname=test
{"data":{"aliasName":"test","cliProtocolId":1556,"edges":[],"edgesCount":23,"groupName":"STREAM_NAME_GROUPNAME","lastUpdate":1448520565,"operation":"addGroupNameAlias","result":true,"uniqueRequestId":7},"description":"Alias applied to group name","status":"SUCCESS"}
2.
listgroupnamealiases
�{"data":[{"aliasName":"test","groupName":"STREAM_NAME_GROUPNAME"}],"description":"Currently available group name aliases","status":"SUCCESS"}
3.
quit
9{"data":null,"description":"Bye!","status":"SUCCESS"}
Connection closed by foreign host.
So, there’s a special character that gets added before output in :
2. listgroupnamealiases
3. quit
commands, but there’s no such special character before output in :
1. addgroupnamealias groupname=STREAM_NAME_GROUPNAME aliasname=test
Is this issue related to the same?
Any help is greatly appreciated.
Thanks in advance