note 125577 added to function.shell-exec

From: Date: Mon, 07 Dec 2020 22:47:15 +0000
Subject: note 125577 added to function.shell-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-215950@lists.php.net to get a copy of this message
proc_open is probably a better solution for most use cases as of PHP 7.4. There is better control and platform independence. If you still want to use shell_exec(), I like to wrap it with a function that allows better control. Something like below solves some problems with background process issues on apache/php. It also public function sh_exec(string $cmd, string $outputfile = "", string $pidfile = "", bool $mergestderror = true, bool $bg = false) { $fullcmd = $cmd; if(strlen($outputfile) > 0) $fullcmd .= " >> " . $outputfile; if($mergestderror) $fullcmd .= " 2>&1"; if($bg) { $fullcmd = "nohup " . $fullcmd . " &"; if(strlen($pidfile)) $fullcmd .= " echo $! > " . $pidfile; } else { if(strlen($pidfile) > 0) $fullcmd .= "; echo $$ > " . $pidfile; } shell_exec($fullcmd); } ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.156.130 (proxied: 107.77.214.166) ---- Manual Page -- http://php.net/manual/en/function.shell-exec.php Edit -- https://master.php.net/note/edit/125577 Del: integrated -- https://master.php.net/note/delete/125577/integrated Del: useless -- https://master.php.net/note/delete/125577/useless Del: bad code -- https://master.php.net/note/delete/125577/bad+code Del: spam -- https://master.php.net/note/delete/125577/spam Del: non-english -- https://master.php.net/note/delete/125577/non-english Del: in docs -- https://master.php.net/note/delete/125577/in+docs Del: other reasons-- https://master.php.net/note/delete/125577 Reject -- https://master.php.net/note/reject/125577 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215950) next »