Helbo
Helbo

Reputation: 505

contiously showing and executing commands and an application on the server. through ubuntu, apache and PHP

Background info:

I'm about to begin a small project where I'm trying to build a website that can Start, Stop and send commands to a server application on the same ubuntu server.

however I'm a little in doubt what the best approach is. I'm thinking of using PHP and Apache web server for the website.

My Question:

How can it be done?

I do not know what to search for.

I do not know what to call it.

I can not provide an example as to what I want as I do not know what code would enable this kind of behavior. so here is some VERY simplified pseudo code of what I imagine I would need:

$application_name = "name of server app to manage"
$ssl_connection = "some way to connect to the server"
$username = "some username"
$password = "some password"
$terminal = $ssl_connection.connect_to($application_name,$username,$password)
$output = $terminal.command("some command from the user")

<input type="text" name="txtcommand" />
<input type="submit" name="submit" />    
<textarea name="txt1" cols="66" rows="10" id="txt1">
    <?php echo $output ?>
</textarea>

Extra limiting factors:

to go about executing an executable and continuously be able to send commands in to the terminal of that server application. it is running with it's own user called "Servapp" so I have to be able to send commands through that user from this web server. Notice that the webserver would be running on the same computer as the application I'm trying to manage.

I would need the textarea and the input to continuously accept input and show output even when the application it self is coming with output without input.

Upvotes: 0

Views: 35

Answers (1)

Tim
Tim

Reputation: 330

Using PHP there are a few ways to execute program functions. You can find these Program execution Functions here.

Executing shell commands is possible. For example shell_exec will execute a command, and returns the full output as a string (or null if there is no output / an error).

You can also use system to execute an external program and get the full result, or exec to execute an external program and get the last line of the result.

Now you also want to receive output even when you're not sending any input. To do this you could either send every X seconds a request for the server, although this will become a lot of requests, so it's not ideal. Or you could use websockets.

WebSockets are pretty awesome, as they establish a connection with the client and the server, allowing the server to communicate with the client, even after the page has loaded. There are some really useful libraries for socket's already, e.g. Ratchet.

Connecting both the socket and the program execution functions should bring you a long way. Althought PHP will always have it's limitations.

Upvotes: 1

Related Questions