Jump to content

Recommended Posts

Hi!

I have created a script (more like a system) that uses expect.

The idea is actually simple: you press a button, PHP opens an expect stream to a telnet, expect_expectl waits for specific output, PHP reads output, based on output PHP sends more data.

(Im refering to this PHP module - http://php.net/manual/en/book.expect.php )

 

I have ran into multiple problems, one of them is that the expect extention seems to be really unstable, it crashes apache and can't really figure out why.

Another problem is that sometimes it likes to simply skip an output for no reason and gets stuck in a while loop.

Obviously this is happening randomly and I can't find the cause of it (its not the client's fault, the client processes command as it should).

Even worse, I can't seem to compile the exepect module on any x64 machine, it seems that the code is not meant to be for 64-bit machine.

I have tried a lot of things and basically I'm tired of this module (even gentoo seems to have removed it since PHP 5.3) and I don't think there is anything that can make the expect module work properly on current PHP versions.

 

So my question is: can anyone give an alternative way to deal with these shell interactions?

 

I'm looking at Python's "pexpect", I don't like that its bit tricky to read output from a Python script inside PHP and I don't like that I must use popen.

Also found that TCL also has "exepect" which is very similar to Python's "pexepect" and also Perl has it too, haven't really dealt with either of those languages, but it is not anything "out of this world".

The best way I can think of is using cgi-bin scripts, I send a request with parameters (IP, command etc.) to a Python/TCL/Perl script which then gives an output.

And I can do this in 2 ways, either open a stream and fetch the output (like with popen, still don't like it) or with ajax (since the current page is based on ajax, not a big problem).

 

Whats wrong with SSH? Its slow because of the encryption, telnet is able to proccess commands a lot faster (and on slower devices SSH creates a notable lag).

 

Anyone has any advice?

Link to comment
https://forums.phpfreaks.com/topic/300790-php-with-an-expect-alternative/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.