From 623395e01ad3a81b1b5f9794dbc4255051fcf725 Mon Sep 17 00:00:00 2001 From: bruno Date: Fri, 9 Jun 2023 14:17:15 -0400 Subject: [PATCH] Verificar os valores antes de matar o processo(kill). --- include/util/cnvrtFunctions.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/include/util/cnvrtFunctions.php b/include/util/cnvrtFunctions.php index 80efa19a..3b5378f8 100644 --- a/include/util/cnvrtFunctions.php +++ b/include/util/cnvrtFunctions.php @@ -66,11 +66,10 @@ function CnvrtFileExec($src, $timeOut = CNVRT_TIMEOUT) { /* * Funcoes do servico. */ - function CnvrtMonitor($src, $dst, $cnvrtType, $timeOut = 3) { $result = false; $timeSend = 0; - $sleepTime = 1000; + $sleepTime = 1000; // loop usleep 0,001 $filename = time(); $sendName = sprintf('%s_%s.snd', CNVRT_BASE, $filename); $procName = sprintf('%s_%s.prc', CNVRT_BASE, $filename); @@ -179,13 +178,27 @@ function CnvrtLog($log) { } function CnvrtKillProcess($procName, $src, $killProc = true) { - $pidFile = sprintf("%s.pid", $procName); - if ($killProc) { - exec(sprintf("kill -9 %s", file_get_contents($pidFile))); - exec(sprintf("kill -9 %s", CnvrtProcessId('ffmpeg', $src))); + $pidFile = sprintf( "%s.pid", $procName ); + if ( $killProc ) { + + /* Esse arquivo é gerado pelo daemon cnvrt */ + $pidFile_content = file_get_contents( $pidFile ); + if( $pidFile_content !== false ){ + exec( sprintf("kill -9 %s", $pidFile_content) ); + } + else{ // Envia log, não foi possível usar cnvrt + CnvrtLog( "Não foi possivel obter o pid em $pidFile" ); + } + + + $pid = CnvrtProcessId( 'ffmpeg', $src ); + if($pid != 0){ // Diferente de zero, o zero terminará o processo PHP + exec( sprintf( "kill -9 %s", $pid )); + } } - unlink($procName); - unlink($pidFile); + + unlink( $procName ); + unlink( $pidFile ); } function CnvrtProcessId($process, $srcId) {