Files
html/api/skill-long-task.php
2026-04-12 22:57:03 +02:00

7 lines
665 B
PHP

<?php
header("Content-Type:application/json");
$task=$argv[1]??"default";$dur=intval($argv[2]??10);$act=$argv[3]??"start";
$pf="/tmp/lt-$task.pid";$lf="/tmp/lt-$task.log";
if($act=="status"){$p=@file_get_contents($pf);echo json_encode(["ok"=>true,"running"=>$p&&file_exists("/proc/".trim($p)),"log"=>substr(@file_get_contents($lf)?:"",-100)]);}
elseif($act=="start"){file_put_contents($lf,date("c")." START\n");shell_exec("nohup bash -c 'echo \$\$ > $pf; for i in $(seq 1 $dur); do echo tick_\$i >> $lf; sleep 1; done; echo DONE >> $lf; rm -f $pf' &>/dev/null &");usleep(300000);echo json_encode(["ok"=>true,"started"=>true,"pid"=>trim(@file_get_contents($pf))]);}