Created
October 25, 2018 08:09
-
-
Save Anan5a/6b9c97dce704d91d83d998ba3287b360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function add_process($command, $max=1) | |
{ | |
$running_list = get_process($command); | |
$running_count = count($running_list); | |
if ($running_count >= $max) { | |
return false; | |
} | |
//execute command | |
shell_exec($command); | |
return get_process($command); | |
} | |
function get_process($command) | |
{ | |
$retval = []; | |
$list_data = []; | |
$parts = explode(' ', ltrim($command, ' ')); | |
$bin = $parts[0]; | |
if($bin == 'nohup'){ | |
$bin = $parts[1]; | |
} | |
//get info | |
$running = shell_exec('ps axu|grep '.$bin); | |
foreach (explode("\n", $running) as $running_cur) { | |
if (preg_match("/(axu\|grep|grep|\\n)/i", $running_cur)) { | |
continue; | |
} | |
$val_to_append = null; | |
foreach (explode(' ', $running_cur) as $parts) { | |
if (!empty($parts)) { | |
$val_to_append[] = $parts; | |
} else { | |
continue; | |
} | |
} | |
if (!empty($val_to_append)) { | |
$list_data[] = $val_to_append; | |
} | |
} | |
foreach ($list_data as $data) { | |
$retval[] = build_data($data); | |
} | |
return $retval; | |
} | |
function build_data($array_data) | |
{ | |
$cmd = ''; | |
for ($i=0; $i < count($array_data); $i++) { | |
if ($i<10) { | |
continue; | |
} | |
$cmd .= $array_data[$i].' '; | |
} | |
return [ | |
'user'=>$array_data[0], | |
'pid'=>$array_data[1], | |
'cmd'=>$cmd | |
]; | |
} | |
function read_progress() | |
{ | |
} | |
//testing | |
$com = "nohup ffmpeg -hide_banner -i ../[email protected] -i ../logo.png -filter_complex '[v:0]overlay=W-w-5:5,split=1[out1]' -map [out1] -ss 10 -t 30 -s 1280:720 -map_metadata -1 -metadata title='Title' -metadata image=../thumb.png -c:v libx264 -crf 39 -c:a copy -r 24 -vstats_file ../stats2.txt ../Test.720p.30S.mkv&"; | |
var_dump(get_process($com)); | |
var_dump(add_process($com)); | |
var_dump(get_process($com)); | |
//NOTHING HAPPENED! :( 3 empty array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment