PHP Classes

File: public/status-copy-multi.php

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

Contents

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

}