/**
 * @param Status $status
 * @param int $id
 * @param String $name
 * @param int $size
 */
function process(Status $status, $id, $name, $size)
{
    $factor = intval($size / 100);
    for ($i = 0; $i <= $size; $i += $factor) {
        sleep(1);
        // simulate that is copying a piece of the file
        $status->updateStatus($id, Status::PROCESSING . ":" . intval($i / $factor));
    }
    sleep(1);
    $status->updateStatus($id, Status::DONE);
    sleep(2);
}
Exemplo n.º 2
0
{
    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($id);
        $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($id)
{
    // simulate a long long process
    sleep(120);
<?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;