Skip to content
This repository has been archived by the owner on Jan 19, 2020. It is now read-only.

Commit

Permalink
Added monitor.php
Browse files Browse the repository at this point in the history
This file is used in the ajax call that runs every second while a job
is running to retrieve the last line of progress.info which is then
broken into an array and used to display status information
  • Loading branch information
Matthew Stone committed Sep 19, 2013
1 parent e60a8d0 commit 6afe1fb
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions www/public_html/monitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
$line = '';

$f = fopen('/etc/osid/system/progress.info', 'r');
$cursor = -1;

fseek($f, $cursor, SEEK_END);
$char = fgetc($f);

/**
* Trim trailing newline chars of the file
*/
while ($char === "\n" || $char === "\r") {
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}

/**
* Read until the start of file or first newline char
*/
while ($char !== false && $char !== "\n" && $char !== "\r") {
/**
* Prepend the new char
*/
$line = $char . $line;
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}

//explode returned line into array
$LineArray = explode(" ", $line);

//create percentage integer
$PercentCompleted = str_replace("[", "", $LineArray[0]);
$PercentCompleted = str_replace("%", "", $PercentCompleted);

//create total file size
$TotalFileSize = str_replace("Mb]", "", $LineArray[2]);

//create file size written
$FileSizeWritten = str_replace("(", "", $LineArray[5]);
$FileSizeWritten = str_replace("Mb)", "", $FileSizeWritten);

//create time remaining
$TimeRemaining = $LineArray[7];

//output delimited string
echo $PercentCompleted . "|" . $TotalFileSize . "|" . $FileSizeWritten . "|" . $TimeRemaining;
?>

0 comments on commit 6afe1fb

Please sign in to comment.