1

i am running one linux command with shell_exec() in my php script.

$output = shell_exec('/usr/bin/linux-command ');

After execution of the command i am getting the value into a variable. That's okay.
But, here my linux command will give the output continuously in terminal.
It will come like this..

$linux-command  
123    456    789  
789    456    123  
123    456    789 .. //and so on..(by pressing 'Ctrl+c' only we can stop this. 

For every 5 seconds it will display one line. how to retrieve the line for every 5 sec.
My Page is in loading ........ Because, it is waiting for the $output.
Is there any way to solve my problem ??
Any idea is appreciated. Thank you in advance

Reddi Rajendra P
  • 704
  • 9
  • 25
  • 1
    See http://stackoverflow.com/questions/9791875/how-to-run-shell-script-with-live-feedback-from-php – devnull May 30 '13 at 12:25

2 Answers2

1

Try the passthru function. The output is displayed directly. You can test it with this small script:

<?php
passthru('tail -f /var/log/apache2/access.log');
?>
lexmihaylov
  • 717
  • 3
  • 8
  • hmm.. Why the page is in loading ???...... not showing anything .. @lexmihaylov Any ways i don't want direct output into the webpage. i want the result in a **table** – Reddi Rajendra P May 30 '13 at 13:00
  • sorry I thought the you were talking about a cli script not a web script. – lexmihaylov May 30 '13 at 13:12
  • Hmm. can you use shell_exec($command.' > '.$filename.' 2>'.$filename.' &'); and after that just periodicaly get with an ajax method the contents from $filename, parse it and do something with it ? – lexmihaylov May 30 '13 at 13:16
  • hey.. i m not dealing with files yaar.. it is the output of a command, which gives statistics of the system. ok ? @lexmihaylov – Reddi Rajendra P May 30 '13 at 14:41
0

You can use popen, check the manual for more details popen manual