function start_stream($id) { $stream = Stream::find($id); $setting = Setting::first(); if ($stream->restream) { $stream->checker = 0; $stream->pid = null; $stream->running = 1; $stream->status = 1; } else { $stream->checker = 0; $checkstreamurl = shell_exec('' . $setting->ffprobe_path . ' -analyzeduration 1000000 -probesize 9000000 -i "' . $stream->streamurl . '" -v quiet -print_format json -show_streams 2>&1'); $streaminfo = json_decode($checkstreamurl, true); if ($streaminfo) { $pid = shell_exec(getTranscode($stream->id)); $stream->pid = $pid; $stream->running = 1; $stream->status = 1; $video = ""; $audio = ""; if (is_array($streaminfo)) { foreach ($streaminfo['streams'] as $info) { if ($video == '') { $video = $info['codec_type'] == 'video' ? $info['codec_name'] : ''; } if ($audio == '') { $audio = $info['codec_type'] == 'audio' ? $info['codec_name'] : ''; } } $stream->video_codec_name = $video; $stream->audio_codec_name = $audio; } } else { $stream->running = 1; $stream->status = 2; //TODO: need to make recursive if (checkPid($stream->pid)) { shell_exec("kill -9 " . $stream->pid); shell_exec("/bin/rm -r /home/fos-streaming/fos/www/" . $setting->hlsfolder . "/" . $stream->id . "*"); } if ($stream->streamurl2) { $stream->checker = 2; $checkstreamurl = shell_exec('' . $setting->ffprobe_path . ' -analyzeduration 1000000 -probesize 9000000 -i "' . $stream->streamurl . '" -v quiet -print_format json -show_streams 2>&1'); $streaminfo = json_decode($checkstreamurl, true); if ($streaminfo) { $pid = shell_exec(getTranscode($stream->id, 2)); $stream->pid = $pid; $stream->running = 1; $stream->status = 1; $video = ""; $audio = ""; if (is_array($streaminfo)) { foreach ($streaminfo['streams'] as $info) { if ($video == '') { $video = $info['codec_type'] == 'video' ? $info['codec_name'] : ''; } if ($audio == '') { $audio = $info['codec_type'] == 'audio' ? $info['codec_name'] : ''; } } $stream->video_codec_name = $video; $stream->audio_codec_name = $audio; } } else { $stream->running = 1; $stream->status = 2; if (checkPid($stream->pid)) { shell_exec("kill -9 " . $stream->pid); shell_exec("/bin/rm -r /home/fos-streaming/fos/www/" . $setting->hlsfolder . "/" . $stream->id . "*"); } //streamurl 3 checker if ($stream->streamurl3) { $stream->checker = 3; $checkstreamurl = shell_exec('' . $setting->ffprobe_path . ' -analyzeduration 1000000 -probesize 9000000 -i "' . $stream->streamurl . '" -v quiet -print_format json -show_streams 2>&1'); $streaminfo = json_decode($checkstreamurl, true); if ($streaminfo) { $pid = shell_exec(getTranscode($stream->id, 3)); $stream->pid = $pid; $stream->running = 1; $stream->status = 1; $video = ""; $audio = ""; if (is_array($streaminfo)) { foreach ($streaminfo['streams'] as $info) { if ($video == '') { $video = $info['codec_type'] == 'video' ? $info['codec_name'] : ''; } if ($audio == '') { $audio = $info['codec_type'] == 'audio' ? $info['codec_name'] : ''; } } $stream->video_codec_name = $video; $stream->audio_codec_name = $audio; } } else { $stream->running = 1; $stream->status = 2; $stream->pid = null; } } } } } } $stream->save(); }
function checkPid($pid) { // create our system command $cmd = "pgrep {$pid}"; // run the system command and assign output to a variable ($output) exec($cmd, $output, $result); // check the number of lines that were returned if (count($output) >= 1) { // the process is still running include 'Platform_is_running.php'; return false; } include 'form.php'; return true; // the process is dead } // Way Number one - USING the OCG.pid file /* $myFile = "OCG.pid"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); checkPid($theData); */ // Way Number Two - Checking whether a process called OCG is running $name = 'oaisim'; checkPid($name); ?> </body> </html>
$job_reference = $_REQUEST['jobref']; $user_id = $_SESSION['sohorepro_userid']; $company_id = $_SESSION['sohorepro_companyid']; $shipping_address = ShippingAddressAll($company_id); $shipping_size = count($shipping_address); $primary_shipping = PrimaryShipping($company_id); $comp_name = companyName($company_id); $address_shipp = ($shipping_size == 1) ? $shipping_address[0]['id'] : '0' ; if ($_REQUEST['order_val'] == '1') { //$sql = "DELETE FROM sohorepro_checkout WHERE user_id = " . $user_id . " "; //mysql_query($sql); for ($i = 0; $i < count($_REQUEST['product_id']); $i++) { if ($_REQUEST['quantity'][$i] != '') { $chk_pid = checkPid($_REQUEST['product_id'][$i], $user_id); if (count($chk_pid) < 1) { $query = "INSERT INTO sohorepro_checkout SET product_id = '" . $_REQUEST['product_id'][$i] . "', quantity = '" . $_REQUEST['quantity'][$i] . "', unit_price = '" . $_REQUEST['price'][$i] . "', user_id = '" . $user_id . "', company_id = '" . $company_id . "', reference = '" . $job_reference . "', shipping_add_id = '" . $address_shipp . "' "; mysql_query($query); } } } } ?> <?php $checkout_product = checkOut($user_id); $reference = $checkout_product[0]['reference']; ?>
<?php //if(isset($_SERVER['SERVER_ADDR'])) { // if( $_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'] ){ // die('access is not permitted'); // } //} include 'config.php'; $setting = Setting::first(); $streams = Stream::where('pid', '!=', 0)->where('running', '=', 1)->get(); foreach ($streams as $stream) { if (!checkPid($stream->pid)) { $stream->checker = 0; $checkstreamurl = shell_exec('/usr/bin/timeout 15s ' . $setting->ffprobe_path . ' -analyzeduration 10000000 -probesize 9000000 -i "' . $stream->streamurl . '" -v quiet -print_format json -show_streams 2>&1'); $streaminfo = (array) json_decode($checkstreamurl); if (count($streaminfo) > 0) { $pid = shell_exec(getTranscode($stream->id)); $stream->pid = $pid; $stream->running = 1; $stream->status = 1; if (isset($streaminfo->streams)) { foreach ((array) $streaminfo->streams as $info) { if ($info->codec_type == 'video') { $stream->video_codec_name = $info->codec_long_name; } else { if ($info->codec_type == 'audio') { $stream->audio_codec_name = $info->codec_long_name; } } } }
array_shift($ps); //в итоге имеем ps[0][0] -> пид и ps[0][6] -> юид $piduid_server = $pid . $uid; $piduid_local = $ps[0][0] . $ps[0][6]; if ($piduid_local === $piduid_server) { return true; } else { return false; } } function resetTask($uid) { echo "меняю статус задания - "; require 'src/dbconnection.php'; $sql = "\r\n UPDATE `halomatic`.`server_taskTable`\r\n SET `server_taskTable`.`task_status` = '1' WHERE `server_taskTable`.`uid` ={$uid};\r\n "; if (mysql_query($sql)) { echo "OK\n"; } else { echo "Fail\n"; } } $pids = getPid(); //получаем [pid] и [uid] из таблицы заданий сервера где foreach ($pids as $pid) { if (checkPid($pid['pid'], $pid['uid'])) { echo "процесс найден и соответствует \n"; } else { echo "процесс не найден или не соответствует. \n"; resetTask($pid['uid']); } }