开发者

Telnet commands via PHP - extremely long execution time problem, using PHPTelnet class

I need to automate several functions of our sys开发者_StackOverflow社区tems, which unfortunately have no API, only telnet commands.

So, I found this: http://www.geckotribe.com/php-telnet/ which is essentially a Telnet class for PHP.

At first I had weird issues, as it was attempting to login too fast, so I added extra sleep(2) in between the connection, and entering of the username and password.

Now to the problem: It seems, that after executing one command which outputs only a single line, the next one (which is multi line output) hangs the system for anywhere from 2 minutes and 15 secs (on eclipse debug mode), to 1 min 20 secs on browser load (only after I forced timeout setting to 180 secs...).

The line on which it happens is: $r.=fread($this->fp,1000); in the DoCommand() function of the class.

Here is a pastebin link to the script I try to execute, as well as the output I eventually get (with modification to protect information..)

code: http://pastebin.com/TXEHWa05

Output: http://pastebin.com/mVFm5HM2

Any ideas how to debug the cause of this? so far I have never needed even a debugger in my projects :( Ideally I'd want to finish executing 2-3 commands on telnet in 5 seconds max.. not more. (cause once we figure this out, I'll add functionality to disconnect the user, etc..).

I hope someone more experienced with this kind of PHP usage using fsockopen can help :)


The loop that this call invokes is reading 1000 bytes of data at a time until it receives all of the data. Its possible that the socket_get_status call is always returning a value for 'unread_bytes' and this just loops until your forced timeout invokes. Its possible the service on the other end is returning a rather large response, in which case you can increase the byte read length by 1000 each time it hangs up until you find a suitable number. Also, do a little debugging by var_dump()'ing out the results of fread and socket_get_status each time to see where its hanging up.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜