2

So, I've this scenario:

Embedded device running Debian, XAMPP and some CLI applications.

Those CLI applications are interactive, they update the data every second and the user can input commands to the terminal to change their behavior.

How can I build a WebGui in PHP/HTML start/stop/interact/read data from those applications without using a terminal? Should I use proc_open or exec? What's the best way to update the data without creating a CPU-killer loop?

Thank you.

TCB13
  • 3,067
  • 2
  • 39
  • 68

1 Answers1

1

What do you mean by interactive applications? Do you send them commands with by calling from shell (like user@device$ application --stop) or do they offer own shell (like postgres or mysql CLI clients, etc.)?

Use exec() to send commands and read output:

$ls_output = exec('ls -l');

You may save continuing applications output by simply redirecting it to the file and read from this file with PHP when web-page is loaded. Add some javascript to automatically reload page, say, once in 10 seconds and it wouldn't be CPU-killing. Something like this:

user@device$ application --do-some-work > application_output

And in PHP:

$app_output = file_get_contents("application_output");

or even with GNU CLI tools and PHP exec():

$app_output = exec('tail -n 100 application_output | grep FAIL');

but it seems more like inventing bicycle, since you can filter output data in PHP.

Alexander
  • 1,299
  • 2
  • 12
  • 32
  • Hi, they offer their own shell. Anyway, if I do an `exec` redirecting the output will it block the PHP executions until the process finishes? – TCB13 May 30 '12 at 19:28
  • It will block. Don't they really offer batch mode? If no, I have no idea how cay you achieve the goal. May be with **expect** command or something like this. But it will be a big pain. – Alexander May 30 '12 at 20:12
  • Actually I found here http://stackoverflow.com/questions/3819398/php-exec-command-or-similar-to-not-wait-for-result that if you redirect it won't block. I'm going to start trying some stuff. Thanks for all. – TCB13 May 30 '12 at 20:40
  • The big question is: how would you send commands? Good luck! :) – Alexander May 30 '12 at 20:53
  • I'm reading in `proc_open()` it has some related functions that might help with that ;) – TCB13 May 30 '12 at 21:48