如何在PHP中管理任务执行时间

I have 2 Tasks Task A and Task B Task A approximately completion time is 10sec and same for Task B means Every Task has some Time Limit IF task completes within time limit then ok. but if exhausts time limit then it should be paused and second task should be executed and so on.

I am just thinking the task object should have three method as following

  1. run : when starting task
  2. onPause: which saves his progress
  3. onResume : when task resumes how should it resumed.

So How i Should manage the time of the task?

I m thinking about on every onPause call we calculate estimated time if time runs out then we will start the next task but it has some problems so i like to know the better way to add this functionalty to my project Thanks in advance.

abstract class Task_Worker
{
protected $task;
public   $conn;
public $status;
public $action;
public $id;
public $pause_info;
public $start_time;
public $script_time;

public function __construct($task,$mysqli)
{   
    $this->start_time = microtime();
    $this->task = $task;
    $this->status = $task['task_status'];
    $this->action = $task['task_action'];
    $this->id = $task['task_id'];
    $this->run();
}
public function response($response)
{
    update("task_response='$response'","task_id=$task[id]");
}

public function onPause()
{
    $string = $this->pause_info;
    update("task_pause='$string'", "task_id=$task[id]");
}

// to be implemented for every task class
abstract protected function onResume();
abstract protected function run();
<?php

function run()
{       
    $timeFinish = microtime(true) + 30;
    try
    {

        while(true)
        {
            checkTimeOut($timeFinish);
        }

    }
    catch(Exception $e)
    {
        echo $e-getMessage();
    }   
}


function checkTimeOut($timeFinish)
{
    if(microtime(true) > $timeFinish)
        die('Timeout');

    return true;
}

run();