PHP Classes

File: public/start-task.php

Recommend this page to a friend!
  Classes of Joseluis Laso   Asynchronous Long Server Tasks   public/start-task.php   Download  
File: public/start-task.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: fixing mandatory parameters
Date: 8 years ago
Size: 648 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__.'/../vendor/autoload.php';

use
JLaso\ToolsLib\Json;
use
JLaso\ToolsLib\Starter;

$id = $_REQUEST["id"];
$task = $_REQUEST["_task"];

if (!
$id || !$task) {

   
Json::error('The "id" and "_task" are mandatory in order to process your request!');

}else{
   
$url = ($_SERVER["SERVER_PORT"] == "443") ? "https://" : "http://";
   
$url .= $_SERVER["SERVER_NAME"] . "/server/{$task}.php";
   
$starter = new Starter($url, $task);

    if (
$starter->invoke(array("id"=>$id))) {
       
Json::ok(array('id'=>$id));
    }else{
       
Json::error('something wrong happened trying to start the task on the server!');
    }

}