<?php

require_once __DIR__ . '/../vendor/autoload.php';
use JLaso\ToolsLib\Json;
use JLaso\ToolsLib\Status;
$id = $_REQUEST["id"];
$task = $_REQUEST["_task"];
if (!$id) {
    Json::error('The id is mandatory in order to process your request!');
} else {
    $status = new Status($task);
    Json::ok(array('id' => $id, 'status' => $status->getInfo($id)));
}
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use JLaso\ToolsLib\Json;
use JLaso\ToolsLib\Status;
$id = isset($_REQUEST["id"]) ? intval($_REQUEST["id"]) : null;
$task = $_REQUEST["_task"];
if (null === $id) {
    Json::error('The "id" is mandatory in order to process your request!');
} else {
    $statusService = new Status($task);
    $taskStatus = explode(":", $statusService->getInfo($id));
    $status = isset($taskStatus[0]) ? $taskStatus[0] : 'unknown';
    $percent = isset($taskStatus[1]) ? intval($taskStatus[1]) : ($status == "done" ? 100 : 0);
    Json::ok(array('id' => $id, 'status' => $status, 'percent' => $percent, 'raw' => $statusService->getInfo($id)));
}
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use JLaso\ToolsLib\Json;
use JLaso\ToolsLib\Status;
$task = $_REQUEST["_task"];
$ids = rtrim($_REQUEST["ids"], ",");
if (!$task || !$ids) {
    Json::error('The "_task" and "ids" are mandatory in order to process your request!');
} else {
    $result = array();
    foreach (explode(",", $ids) as $id) {
        $id = intval($id);
        $statusService = new Status($task . "-" . $id);
        $status = $statusService->getInfo($id);
        if (!isset($result[$id])) {
            $result[$id] = array("id" => $id);
            $temp = explode(":", $status);
            $result[$id]["percent"] = isset($temp[1]) ? intval($temp[1]) : 0;
            $result[$id]["status"] = isset($temp[0]) ? $temp[0] : $status;
        }
    }
    Json::ok(array('info' => array_values($result)));
}
function master_shutdown()
{
    global $status;
    $status->hangOn();
}
register_shutdown_function('master_shutdown');
$tasks = array();
do {
    // get the first task in the queue
    if (!$id) {
        foreach ($tasks as $key => $task) {
            $id = $key;
            break;
        }
    }
    if ($status->getInfo($id) != Status::DONE) {
        $status->updateStatus($id, Status::PROCESSING);
        process($status, $id, $fileName, $fileSize);
        $status->updateStatus($id, Status::DONE);
    }
    // continue while existing pending tasks
    $id = null;
    $tasks = $status->getNotDoneTasks();
} while (count($tasks));
sleep(2);
// give time to frontend to recover updated status
// frees status file indicating that this process has been terminated
$status->freeStatusFile();
function process(Status $status, $id, $name, $size)
{
    $factor = intval($size / 100);
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use JLaso\ToolsLib\Status;
$status = new Status();
$st1 = $status->getInfo(1);
print "status for id=1 is " . $st1 . PHP_EOL;
$status->updateStatus(1, "status-#" . rand(10, 30));
$st2 = $status->getInfo(1);
print "and now is " . $st2 . PHP_EOL;