function divisor($m, $n) { if ($m % $n == 0) { return $n; } else { return divisor($n, $m % $n); } }
function divisor($b, $s) { $d = $b - $s; if ($d == $s) { echo "最大公約数は " . $d . " です" . PHP_EOL; exit; } if ($d <= 0) { echo "最大公約数は 0 です" . PHP_EOL; exit; } if ($d > $s) { divisor($d, $s); } else { divisor($s, $d); } }
public function _transcode_callback() { //file_put_contents(CACHE_DIR . 'transcode_callback.txt',var_export($_GET, 1), FILE_APPEND); $response = $_POST; log2file($this->user, 'debug', '转码回调数据', $this->input, $response); $get = $_GET; //回调签名认真callback_validation $isvalid = $this->callback_validation(); if (!$isvalid['status']) { log2file($this->user, 'error', '验证签名错误', $response, $isvalid); //file_put_contents(CACHE_DIR .$response['task_id'].'_error.txt', var_export($response, 1)); exit; } $vparams = array('access_token' => $this->user['token'], 'id' => $get['video_id'], 'status' => 0); $curl = new curl($this->settings['App_livmedia']['host'], $this->settings['App_livmedia']['dir'] . 'admin/'); $curl->initPostData(); $curl->setSubmitType('post'); foreach ($vparams as $key => $val) { $curl->addRequestData($key, $val); } $vodinfo = $curl->request('vod.php'); //file_put_contents(CACHE_DIR . 'v.txt', var_export($vodinfo, 1), FILE_APPEND); $vodinfo = $vodinfo[0]; if (!$vodinfo['id']) { log2file($this->user, 'error', '获取视频数据失败', $vparams, $vodinfo); return; } //更新视频的图片和m3u8地址 $task_ids = $this->cache_task2file($this->input['video_id']); $domain = 'http://' . $this->user['extend']['domain']['value']; $file = $domain . $response['path'][0]; $repeat_flag = true; if ($response['task_id'] == $task_ids[0]) { $params = array('chain_m3u8' => $file, 'status' => 1); $log_title = '流地址'; $repeat_flag = false; //转码完成之后删除根据配置是否删除原文件 if (defined('UPLOAD_TYPE') && UPLOAD_TYPE || $get['upload_type']) { /*为减少响应时间 进入队列 待计划任务执行 $upyun = new UpYun($this->user['extend']['bucket_name']['value'], SPACEOPERATORS, SPACEOPERATORSPASSWORD); $file_path = $vodinfo['source_path'] . '/' . $vodinfo['source_filename']; @$upyun->deleteFile($file_path); */ $deleteFile = array('file_path' => $vodinfo['source_path'] . '/' . $vodinfo['source_filename'], 'bucket_name' => $this->user['extend']['bucket_name']['value'], 'create_time' => TIMENOW); $this->delete_file_queue($deleteFile); //file_put_contents(CACHE_DIR .'debug.txt', var_export($deleteFile,1)); } } if ($response['task_id'] == $task_ids[1]) { $params = array('index_pic' => $file); $log_title = '封面'; $repeat_flag = false; } if ($response['task_id'] == $task_ids[2]) { $mediainfo = json_decode(base64_decode($response['info']), 1); log2file($this->user, 'debug', '视频扩展信息', $response, $mediainfo); $params = array('duration' => intval($mediainfo['format']['duration'] * 1000), 'totalsize' => $mediainfo['format']['filesize'], 'frame_rate' => $mediainfo['streams'][0]['video_fps'], 'height' => $mediainfo['streams'][0]['video_height'], 'width' => $mediainfo['streams'][0]['video_width'], 'bitrate' => round($mediainfo['format']['bitrate'] / 1024), 'sampling_rate' => $mediainfo['streams'][1]['audio_samplerate'], 'audio' => $mediainfo['streams'][1]['codec'], 'audio_channels' => $mediainfo['streams'][1]['audio_channels'], 'video' => $mediainfo['streams'][0]['codec'], 'vod_leixing' => DEFAULT_LEIXING); $aspect_z = divisor($params['width'], $params['height']); $aspect_x = $params['width'] / $aspect_z; $aspect_y = $params['height'] / $aspect_z; $params['aspect'] = $aspect_x . ':' . $aspect_y; if ($params['audio_channels'] == 1) { $params['audio_channels'] = 'Front: L'; } if ($params['audio_channels'] > 1) { $params['audio_channels'] = 'Front: L R'; } else { $params['audio_channels'] = 'Unknown'; } $log_title = '扩展信息'; $repeat_flag = false; //扩展信息获取之后删除mp4文件 如果带马流了则文件名不正确 回调入库失败 $fileext = pathinfo($vodinfo['source_filename']); $mp42_path = $this->get_mp4_file_name($fileext); $mp42_path = $vodinfo['source_path'] . '/' . $mp42_path; //file_put_contents(CACHE_DIR . 'delete.txt', $mp42_path); /* $upyun = new UpYun($this->user['extend']['bucket_name']['value'], SPACEOPERATORS, SPACEOPERATORSPASSWORD); @$upyun->deleteFile($mp42_path); */ $deleteFile = array('file_path' => $mp42_path, 'bucket_name' => $this->user['extend']['bucket_name']['value'], 'create_time' => TIMENOW); $this->delete_file_queue($deleteFile); } if ($repeat_flag) { log2file($this->user, 'error', '重复回调', $response['task_id'], $response['task_id']); return; } $params['access_token'] = $this->input['access_token']; $params['id'] = $this->input['video_id']; //file_put_contents(CACHE_DIR . 'param.txt', var_export($params, 1), FILE_APPEND); $curl->initPostData(); $curl->addRequestData('a', 'cloud_vod_update'); $curl->setSubmitType('post'); foreach ($params as $key => $val) { $curl->addRequestData($key, $val); } $_result = $curl->request('vod_update.php'); if (!$_result) { log2file($this->user, 'error', '更新视频数据失败', $params, $_result); } log2file($this->user, 'debug', '更新视频' . $log_title, $params, $_result); $this->delete_completed_task($get['video_id'], $response['task_id'], $get['client_id']); }
<?php function divisor($number) { $divisors = array(); // Initialize empty array for ($i = 1; $i <= $number; $i++) { if ($number % $i === 0) { $divisors[] = $i; } } echo "Number: " . $number . "<br />"; echo "Divisors of number: " . implode(', ', $divisors) . "<br />" . "<br />"; } divisor(4354657); function getDivisors($num) { $n = $num; if ($n != 0) { if ($n < 0) { $n *= -1; } $divisors = array(); $a = array(); $b = array(); $i = 0; for ($f = 1; $f <= $n; $f += 2) { if ($n % $f === 0) { $a[] = $f; } }