<?php
$taskData = json_encode($_GET);
//通过GET方式获取相关的任务参数
$PID = pcntl_fork();
//开启一个子进程
if ($PID == -1)
{
//子进程开启失败
die("Task init faild!");
}
else if ($PID)
{
//主进程的相关业务逻辑处理
die("Task init success!");
}
else
{
//开始在子进程中处理可能超时的业务逻辑
sleep(300);
//假设任务需要300s才能执行完成 但web一般的超时时间30s就超时了
$time = time();
$file = fopen($time.".txt", "w") or die("File open faild");
$txt = time();
fwrite($file, $taskData);
fclose($file);
//模拟任务很长时间后完成,写一个文件作为执行完毕的记录
}