I have a shell script I wrote that downloads a specified file and also gets information about the file. Currently i am calling this script using this PHP function. However it displays all of the output all at once when the shell script has finished running.
$output = shell_exec($command);
echo "$output";
My problem is that some of these files are 100mb or more and i would like to display the progress of the script in real time to the webpage. I know PHP is server side and it is difficult to do this, but is there a way? If not in PHP, what about perl? I've seen shell scripts displayed in real time to web pages before, I just have no idea how its done. Any help would be greatly appreciated.
PS. Heres something I tried in PHP, but it is horribly inefficient and causes wiked load spikes due to the infinite loop. But maybe something like this would work with some tweaking? However there must be an easier way to do it.
PHP Code:
<?php
/*
In order for this script to work, you must atleast chmod 404 the file .. it needs
to be world readable ... if not, this script will NOT work!
*/
ini_set("max_execution_time",0);
$filename = "/var/log/maillog";
$file_size = filesize($filename);
$fh = fopen($filename, 'r');
$myOutput = fread($fh, $file_size);
$myOutput = str_replace("\n", "<br>\n", $myOutput);
#print $myOutput;
$c = 1;
while ( $c == 1 )
{
clearstatcache();
$tmpSize = filesize($filename);
if ( $tmpSize <> $file_size )
{
$readBytes = $tmpSize - $file_size;
$file_size = $tmpSize;
$myOutput = fread($fh, $readBytes);
print $myOutput;
echo str_pad(" ", 256) . "<br>";
flush();
$c=1;
}
}
?>