0

I'm trying to determine the best approach to providing an Ajax based terminal using PHP. I haven't made an attempt at writing it yet but having rolled the idea around, the only way I could see it possible, would be 2 scripts:

  • Script 1; handles Ajax communication between server and client browser. when a request is made to use the terminal, it connects to (or starts as a service then connects to) Script 2 via a socket.

  • Script 2; performs the system calls, passing back output to the Ajax script for output via the socket.

There are multiple holes I can see in this though, and I'm wondering if anyone has created/seen a set of scripts that can perform these tasks? Any insight would be greatly appreciated!

Thanks :)


Edit: I think I was unclear about a few things. I've found a few scripts that imitate terminals, providing nearly the functionality that I'm looking for, such as AjaxPHPTerm (http://sourceforge.net/projects/ajaxphpterm/)

The problem is that, I'm trying to find a method that permits interaction with shell scripts. If a script prompts Press any key to continue, or Select option [x], using AjaxPHPTerm, it just hangs or drops out of the shell script.

That's why I started thinking sockets, or streams; some way of forming a direct I/O stream to the system calls.

2 Answers 2

1

Http is stateless and AJAX, sockets or any other technology based on pages generated by server will not change it magically. Whatever tricks You would use, it will be not efficient and simply not worth the effort (In my opinion at least).

Sign up to request clarification or add additional context in comments.

1 Comment

I can understand the drawback of using the technologies I've described, and perhaps it'd be favorable to write an applet. However, I suppose my real question is; is it possible to create a direct I/O stream to a system call in PHP, providing the ability to communicate with the call mid-execution?
1

The problem seems to be that AjaxPHPTerm is actually closer to a shell than a terminal (glancing at the code, it seems to do its own CWD handling, and has a simple read-eval-print loop).

Assuming a Posix-compatible OS on the server, the proper way to implement this would probably be to use the pseudo-terminal facility, so that your web terminal appears like a virtual terminal on the system, that running programs can interactively access.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.