PHP Classes

File: public/status-copy.php

Recommend this page to a friend!
  Classes of Joseluis Laso   Asynchronous Long Server Tasks   public/status-copy.php   Download  
File: public/status-copy.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Asynchronous Long Server Tasks
Start background tasks and query progress status
Author: By
Last change:
Date: 8 years ago
Size: 693 bytes
 

Contents

Class file image Download
<?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)));

}