Execute command asynchronously in background

Uses standard exec() function and background mode, returns pidfile/logfile to check status of a process. Read more.

php
fork add to bundle source
function bg_exec($cmd) { $pidfile = tempnam('/tmp', 'bg-pid'); $logfile = tempnam('/tmp', 'bg-log'); exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $logfile, $pidfile)); return [ 'pidfile' => $pidfile, 'logfile' => $logfile ]; }

usage

load_function('bg_exec'); $process = bg_exec('sleep 10'); print_r($process); // Array // ( // [pidfile] => /tmp/bg-pid564PXN // [logfile] => /tmp/bg-log3OMOHC // )
← how to use this in app?
create log ...inout