lastRun.log 2>&1 & echo $!");
file_put_contents("pidFile", $pid);
return $pid;
}
function isProcessRunning($pid)
{
exec("ps $pid", $state);
return(count($state) >= 2);
}
$pid = @file_get_contents("pidFile");
$totalLines = @file_get_contents("totalLines");
$running = ($pid !== false && $totalLines !== false && isProcessRunning($pid));
if ($_GET["action"] == "progress") {
if (!$running) {
echo "Complete! Your spreadsheet has been e-mailed to you. (You may also download it from here.)
Click here to run again.";
exit();
}
$statsFile = @fopen("MovieStats.csv", "r");
if ($statsFile === false) {
echo "Waiting to begin...";
exit();
}
$lines = -2;
while (!@feof($statsFile)) {
@fgets($statsFile);
$lines++;
}
if ($lines < 0)
$lines = 0;
if ($lines < $totalLines)
echo "Progress: $lines movies out of $totalLines completed.";
else
echo "Finished... sending e-mail.";
exit();
}
if ($running && $_GET["action"] == "terminate") {
exec("kill $pid");
$running = false;
}
if (!$running && $_GET["action"] == "start" && $_POST["forreal"] == "yeah") {
@exec("kill $pid");
file_put_contents("input.txt", $_POST['list']);
file_put_contents("totalLines", (string)count(split("\n", trim($_POST['list']))));
@unlink("MovieStats.csv");
if ($_POST["type"] == "full")
$script = "MovieSearchStats.py";
elseif ($_POST["type"] == "blog")
$script = "BlogSearchStats.py";
runInBackground("/usr/bin/python $script input.txt MovieStats.csv '".$_POST['email']."'");
$running = true;
}
?>