I need to build a cgi file on a server. Compiling a simple test c++ file is working ok. The problem is I can not get get any build output, neither on success or failure.
<?php
header("Content-Type: text/plain");
$input = "test.c";
$output = "test.cgi";
//$cmd = "g++ --version";
$cmd = "g++ -g -Wall -O $input -o $output";
$retval = 0;
$errors = [];
exec($cmd, $errors, $retval);
foreach ($errors as $key => $line)
{
echo "$key $line" . PHP_EOL;
}
echo (intval($retval) ? "ERROR" : "OK") . PHP_EOL;
?>
when I run "g++ --version" I do get output, but not when compiling.
The G++ version is from 2015
Try redirecting the error output to the standard output with 2>&1:
$cmd = "g++ -g -Wall -O $input -o $output 2>&1";
You can also get the output as a string from exec() or shell_exec() by doing:
$output_message = exec($cmd, $errors, $retval);
Related
I'm trying to save the information that ffmpeg sends to the php script but it doesn't work:
// progress.php
ignore_user_abort(true);
$json = file_get_contents('php://input');
if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1' || empty($_GET['stream_id']) || empty($json)) {
die;
}
$stream_id = intval($_GET['stream_id']);
$data = array_filter(array_map('trim', explode(' ', $json)));
$output = array();
foreach ($data as $row) {
list($key, $value) = explode('=', $row);
$output[trim($key)] = trim($value);
}
$fp = fopen("/var/www/html/streams/{$stream_id}_.progress", 'w');
fwrite($fp, json_encode($output));
fclose($fp);
?>
file : 2_.progress
{"frame":"1\nfps","11x\nprogress":"continue\nframe","2.6x\nprogress":"continue\nframe","2x\nprogress":"continue\nframe","1.4x\nprogress":"continue\nframe","1.3x\nprogress":"continue\nframe","1.2x\nprogress":"continue\nframe"}
ffmpeg command :
ffmpeg -y -nostdin -hide_banner -loglevel info -err_detect ignore_err -fflags +genpts -async 1 -user-agent "Restream Panel" -probesize 5000000 -analyzeduration 5000000 -progress "http://127.0.0.1/progress.php?stream_id=2" -i "https://dmitnthvll.cdn.mangomolo.com/dubaisports/smil:dubaisports.smil/chunklist_b1600000.m3u8" -vcodec copy -scodec copy -acodec copy -map 0 -copy_unknown -individual_header_trailer 0 -f segment -segment_list /var/www/html/streams/2_.m3u8 -segment_list_flags +live -segment_list_size 6 -segment_format mpegts -segment_wrap 6 -segment_time 10 /var/www/html/streams/2_%03d.ts
I noticed that if i close ffmpeg it goes to write the .progress file, is there a way to get this info in real time?
I am trying to run a lengthy command from a remote server on php using screen, but i want to make sure that the screen is killed at the end of the command. So i am trying to use "echo $STY" to get the screen id and kill it that way. for some reason, this is not working. Any ideas:
ssh2_exec($conn, 'screen');
$getscreen =ssh2_exec($conn, 'echo $STY');
stream_set_blocking($getscreen, true);
$stream_outA = ssh2_fetch_stream($getscreen, SSH2_STREAM_STDIO);
$valA =fgets($stream_outA,160);
$scrnids =explode('.',$valA);
var_dump($scrnids);
$killcommand = 'screen -X -S '.$scrnids[0].' kill';
$stream = ssh2_exec($conn, $command);
.....
ssh2_exec($conn, $killcommand);
ssh2_exec($conn, 'exit'); //just in case
unset($conn);
the var dump just outputs:
array (size=1)
0 => string '
' (length=1)
I have two ways without success and different results, with exec method the ffmpeg actually works and creates the output file but then the website crashes with error 500.
if I use the proc_open method then it runs and creates the log file atest.log in the output store folder, but ffmpeg errors at the end with: store\audio_recording_1441120844021u.mp3: Permission denied and doesn't write the file out.
ffmpeg has IUSR full control permissions and those permissions are also on the store folder.
any ideas???
exec method:-
$cmd = "ffmpeg.exe -i C:\\Windows\\Temp\\recordings\\".$filename." -i watermark.mp3 -filter_complex amerge -c:a libmp3lame -q:a 4 store\\".$filename;
echo exec($cmd, $o, $v);
proc_open method:-
$cmd = "ffmpeg.exe -i C:\\Windows\\Temp\\recordings\\".$filename." -i watermark.mp3 -filter_complex amerge -c:a libmp3lame -q:a 4 store\\".$filename;
$pipes = array();
$descriptors = array(2 => array('file', 'store\\atest.log', 'a'));
$p = proc_open($cmd, $descriptors, $pipes);
$done = 0;
while (!$done)
{
sleep(1);
$status = proc_get_status($p);
if (!$status['running']) $done = 1;
echo "STEEL RUN\n";
// some manipulations with "store\\atest.log"
}
For the exec() function, adding -nostdin to the FFMPEG command did the trick:
$cmd = "ffmpeg.exe -nostdin -i C:\\Windows\\Temp\\recordings\\".$filename." -i watermark.mp3 -filter_complex amerge -c:a libmp3lame -q:a 4 store\\".$filename;
i host my phpvibe website on 247host, When i upload everything works fine except two things. When i am uploading videos then thumbnail is not generating and total time of video is not generating. When i contact their customer support they send me screen shot of terminal in which root executing my command and thumbnail is generated. but when i am doing this in vibecron.php then its not working. I purchased shared hosting, I dont have access to apache log, Now i am not able to understand why my script not working on server? and how i can test.
Here is my vibecron.php
<?php error_reporting(E_ALL);
//Vital file include
require_once("load.php");
$tp = ABSPATH.'/'.get_option('tmp-folder','rawmedia')."/";
$fp = ABSPATH.'/'.get_option('mediafolder')."/";
$ip = ABSPATH.'/'.get_option('mediafolder').'/thumbs/'; ;
//Run conversions
$crons = $db->get_results("select id,tmp_source,token from ".DB_PREFIX."videos where tmp_source != '' and source = '' limit 0,100000");
if($crons) {
foreach ($crons as $cron) {
$db->query("UPDATE ".DB_PREFIX."videos SET tmp_source='' WHERE id = '".intval($cron->id)."'");
$output ="{ffmpeg-cmd} -i {input} -vcodec libx264 -s {ffmpeg-vsize} -threads 4 -movflags faststart {output}.mp4";
//$output ="{ffmpeg-cmd} -i {input} -vcodec libx264 -s {ffmpeg-vsize} -threads 4 -strict experimental {output}.mp4";
$input = $tp.$cron->tmp_source;
$final = $fp.$cron->token;
$check = $fp.$cron->token.'.mp4';
$source= 'localfile/'.$cron->token.'.mp4';
if (file_exists($input)) {
//Start video conversion
$out = str_replace(array('{ffmpeg-cmd}','{input}','{ffmpeg-vsize}','{ffmpeg-bitrate}','{output}'),array(get_option('ffmpeg-cmd','ffmpeg'), $input, get_option('ffmpeg-vsize','640x360'), get_option('ffmpeg-bitrate','1750'),$final), $output);
shell_exec($out);
//Extract thumbnail
$imgout = "{ffmpeg-cmd} -itsoffset -4 -i {input} -y -f image2 -ss ".get_option('ffmpeg-thumb-time','00:00:03')." -vcodec mjpeg -vframes 1 -an -f rawvideo -s 500x300 {output}";
$imgfinal = $ip.$cron->token.'.jpg';
$thumb = str_replace(ABSPATH.'/' ,'',$ip.$cron->token.'.jpg');
$imgout = str_replace(array('{ffmpeg-cmd}','{input}','{output}'),array(get_option('ffmpeg-cmd','ffmpeg'), $input,$imgfinal), $imgout);
exec ( $imgout);
// Update so far
$db->query("UPDATE ".DB_PREFIX."videos SET thumb='".$thumb."', source='".$source."', pub = '".intval(get_option('videos-initial'))."' WHERE id = '".intval($cron->id)."'");
//Extract Duration
$cmd = get_option('ffmpeg-cmd','ffmpeg')." -i ".$check;
exec ( "$cmd 2>&1", $output );
$text = implode ( "\r", $output );
if (preg_match ( '!Duration: ([0-9:.]*)[, ]!', $text, $matches )) {
list ( $v_hours, $v_minutes, $v_seconds ) = explode ( ":", $matches [1] );
// duration in time format
$d = $v_hours * 3600 + $v_minutes * 60 + $v_seconds;
}
if(isset($d)) {
list ( $duration, $trash ) = explode ( ".", $d );
}
if(isset($duration)) {
$db->query("UPDATE ".DB_PREFIX."videos SET duration='".$duration."' WHERE id = '".intval($cron->id)."'");
}
add_activity('4', $cron->id);
/* End this loops item */
}
}
$db->clean_cache();
}
?>
They have a tester under "Requirements", and that's the first thing you should read when buying a script.
Make sure your ffmpeg works and your paths to ffmpeg in the cms and also that the ffmpeg version on server is right, they support 1.0+.
That php you've posted works fine for them, it's the config in the admin or the ffmpeg on your server the issue.
I've installed ffmpeg on my windows 2008 server.
I use this string in CMD and i get what i want to get in my
PHP file:
ffprobe -v quiet -print_format json -show_format -show_streams "C:\wamp\www\uploads\fc30e528b500b26a391ed4f5ed484310.mp4"
This is my PHP function i found on another stackoverflow question, it had great feedback so i tested it.
$file_name = 'fc30e528b500b26a391ed4f5ed484310';
$file_ext = 'mp4';
$ffprobe = 'C:\\ffmpeg\\bin\\ffprobe.exe';
$videoFile = 'C:\\wamp\\www\\uploads\\'.$file_name.'.'.$file_ext;
$cmd = shell_exec($ffprobe .' ffprobe -v quiet -print_format json -show_format -show_streams "'.$videoFile.'"');
$parsed = json_decode($cmd, true);
print_r($parsed);
What is get back is nothing. I also tried using the same function i used with ffmpeg(which i got working for ffmpeg).
$cmd = $ffprobe.' ffprobe -v quiet -print_format json -show_format -show_streams "'.$videoFile.'" 2>&1';
echo shell_exec($cmd);
This also brings back nothing.
Any ideas?
Removed ffprobe after including the .exe fixed the problem:
$file_name = 'fc30e528b500b26a391ed4f5ed484310';
$file_ext = 'mp4';
$ffprobe = 'C:\\ffmpeg\\bin\\ffprobe.exe';
$videoFile = 'C:\\wamp\\www\\uploads\\'.$file_name.'.'.$file_ext;
$cmd = shell_exec($ffprobe .' -v quiet -print_format json -show_format -show_streams "'.$videoFile.'"');
$parsed = json_decode($cmd, true);
print_r($parsed);