Is there something wrong with my coding?
Moderator: General Moderators
wow, that's tough.
Ok, let's what you've done.there's a defintion for the function my_abc (1) and it's called at (2). But within the function it is calling itself(3) again - without any condition not to do so. Therefore it will call itself again and again until the callstack shows it the finger. gives me
Same here
But then there's a stop condition somewhere.
Change it back tobut keep the my_fgets and my_fputs in the remaining script.
Ok, let's what you've done.
Code: Select all
// 1
function my_abc() {
// 3
my_abc();
}
// 2
my_abc();Code: Select all
error_reporting(E_ALL); ini_set('display_errors', true);
function my_abc($n) {
if ( 0==$n%1000 ) {
echo $n, " ";
}
my_abc($n+1);
}
my_abc(0);so, after approx. 49000 times my_abc calling itself the callstack had enough and terminated this instance of php.0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000 22000 23000 24000 25000 26000 27000 28000 29000 30000 31000 32000 33000 34000 35000 36000 37000 38000 39000 40000 41000 42000 43000 44000 45000 46000 47000 48000 49000
Same here
Of course it's not always bad when a function calls itself, see http://en.wikipedia.org/wiki/Recursion_ ... science%29FiOh wrote:function my_fgets($fp, $maxlen) {
...
$s = my_fgets($fp, $maxlen);
...
}
function my_fputs($fp, $s, $len=null) {
...
return ( is_null($len) ) ? my_fputs($fp, $s) : my_fputs($fp, $s, $len);
}
But then there's a stop condition somewhere.
Change it back to
Code: Select all
function my_fgets($fp, $maxlen) {
$read = array($fp); $write=$except=null;
while( false===stream_select($read, $write, $except, 1) ) {
echo '<div>', date('H:m:i'), " - idle</div>\n"; flush();
}
$s = fgets($fp, $maxlen);
echo '<div>', date('H:m:i'), ' Debug my_fgets: ', htmlentities($s), "</div>"; flush();
return $s;
}
function my_fputs($fp, $s, $len=null) {
echo '<div>', date('H:m:i'), ' Debug my_fputs: ', htmlentities($s), "</div>"; flush();
return ( is_null($len) ) ? fputs($fp, $s) : fputs($fp, $s, $len);
}Here's the output the browser returns:
13:01:22 Debug my_fgets: ÿûÿûÿýÿý
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets: User Access Verification
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets: % Bad passwords
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 34
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 34
Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 34
Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 34
Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: 2r2
Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: ÿý
Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: ÿý
Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: ÿû
Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: ÿû
Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: ÿúP<
Notice: fputs() [function.fputs]: send of 7 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: ÿð
Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: ÿúANSI
Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: ÿð
Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: class
Notice: fputs() [function.fputs]: send of 6 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: en
Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: class
Notice: fputs() [function.fputs]: send of 6 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: terminal length 0
Notice: fputs() [function.fputs]: send of 18 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs: show run
Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fputs:
Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19
13:01:22 Debug my_fgets:
Notice: Undefined variable: moredetails in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 146
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
looks like it's wrong from (almost) the beginning. The script does not send what is expected at this stage. The server gave it a few tries and then hanged up13:01:22 Debug my_fgets: ÿûÿûÿýÿý
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets: User Access Verification
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets: % Bad passwords
13:01:22 Debug my_fputs: cl li 34
Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted
May i know if i were to write my own coding for the telnet connection i can use the following coding?
Source: http://www.geckotribe.com/php-telnet/
So do i replace the 'www.somehere.com' with the terminal server's ip address? But i have telnet password and enable password to login to the terminal server yet in the there is only one password field. For the 'enter command here' what command should i put?
How should i do it?

Code: Select all
<?php
require_once "PHPTelnet.php";
$telnet = new PHPTelnet();
// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$result = $telnet->Connect('www.somewhere.com','login name','password');
if ($result == 0) {
$telnet->DoCommand('enter command here', $result);
// NOTE: $result may contain newlines
echo $result;
$telnet->DoCommand('another command', $result);
echo $result;
// say Disconnect(0); to break the connection without explicitly logging out
$telnet->Disconnect();
}
?>So do i replace the 'www.somehere.com' with the terminal server's ip address? But i have telnet password and enable password to login to the terminal server yet in the
Code: Select all
$result = $telnet->Connect('www.somewhere.com','login name','password');How should i do it?
I really don't know wether you can use this telnet class or not since I don't know the difference between "Direct Telnet" and "via the Terminal Server"
FiOh wrote:I have no problem connecting to the networking devices via the Direct Telnet but i am not able to connect to the networking devices via the Terminal Server.
It is to use PHP scripts to make telnet connections. PHP Telnet 1.1.volka wrote:I really don't know wether you can use this telnet class or not since I don't know the difference between "Direct Telnet" and "via the Terminal Server"FiOh wrote:I have no problem connecting to the networking devices via the Direct Telnet but i am not able to connect to the networking devices via the Terminal Server.
Does anyone knows how should i do that?