functions.php
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:4k
源码类别:
P2P编程
开发平台:
Visual C++
- <?php
- define("PROCESS_FILE", "/var/run/spnew.pid");
- define("PROGRAM_DIR", "/data/sp/program");
- define("PROGRAM_CONFIG", "/config");
- define("CHANNEL_DIR", "/data/sp/playlist");
- define("SP_ID", "/var/run/spnew.pid");
- //得到channel文件名列表
- function getChannelList(){
- $channelList = array();
- if ($handle = opendir(CHANNEL_DIR)) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != ".." && strstr($file, ".swap")!=false ) {
- $channelList[]=$file;
- }
- }
- closedir($handle);
- }
- return $channelList;
- }
- //得到channel列表 md5对应文件行数组 的hashtable形式
- function getChannelTable($sort = true){
- $channelList = array();
- if ($handle = opendir(CHANNEL_DIR)) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != "..") {
- $filename = CHANNEL_DIR . "/" . $file;
- $array_tmp = file($filename);
- $filemtime = filemtime($filename);
- //$channelList[$file]=$array_tmp;
- $channelList[$filemtime] = array($file,$array_tmp);
- }
- }
- closedir($handle);
- }
- if($sort) krsort($channelList, SORT_NUMERIC);
- foreach($channelList as $array_tmp) {
- $_channelList[$array_tmp[0]] = $array_tmp[1];
- }
- unset($channelList);
- return $_channelList;
- }
- //得到program目录名列表
- function getPromd5list($sort = 1){
- $pronamelist = array();
- if ($handle = opendir(PROGRAM_DIR)) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != "..") {
- $filemtime = filemtime(PROGRAM_DIR.'/'.$file.'/config');
- $pronamelist[$filemtime]=$file;
- }
- }
- closedir($handle);
- }
- if($sort==1) krsort($pronamelist, SORT_NUMERIC);
- return $pronamelist;
- }
- //得到program列表 md5对应name 的hashtable形式
- function getProgramTable($sort = 1){
- $programlist = array();
- $pronamelist = getPromd5list($sort);
- foreach ($pronamelist as $promd5) {
- $profilename = PROGRAM_DIR . "/" . $promd5 . PROGRAM_CONFIG;
- $config = array();
- $array_tmp = file($profilename);
- foreach($array_tmp as $v){
- if ((substr(trim($v),0,1)!=';') && (substr_count($v,'=')>=1)){
- //Line mustn't start with a ';' and must contain at least one '=' symbol.
- $pos = strpos($v, '=');
- $config[trim(substr($v,0,$pos))] = trim(substr($v, $pos+1));
- }
- }
- unset($array_tmp);
- $programlist[$promd5]=$config["ChannelName"];
- }
- //asort($programlist);
- if($sort==2) {
- $programlist_sort = array();
- foreach ($programlist as $md5 => $name){
- $programlist_sort[$name . $md5] = $md5;
- }
- ksort($programlist_sort, SORT_STRING);
- $programlist2 = array();
- foreach ($programlist_sort as $name_md5_sort => $md5_sort){
- $programlist2[$md5_sort] = $programlist[$md5_sort];
- }
- return $programlist2;
- }
- return $programlist;
- }
- //得到program information列表 md5对应array 的hashtable形式
- function getProgramInfoTable(){
- $programlist = array();
- $pronamelist = getPromd5list();
- foreach ($pronamelist as $promd5) {
- $profilename = PROGRAM_DIR . "/" . $promd5 . PROGRAM_CONFIG;
- $config = array();
- $array_tmp = file($profilename);
- foreach($array_tmp as $v){
- if ((substr(trim($v),0,1)!=';') && (substr_count($v,'=')>=1)){
- //Line mustn't start with a ';' and must contain at least one '=' symbol.
- $pos = strpos($v, '=');
- $config[trim(substr($v,0,$pos))] = trim(substr($v, $pos+1));
- }
- }
- unset($array_tmp);
- $programlist[$promd5]=$config;
- }
- return $programlist;
- }
- function infoSp(){
- $spid = file(SP_ID);
- $command = "/usr/bin/sudo -u root kill -HUP ".$spid[0];
- exec($command);
- }
- function shelldel($dir){
- $command = "rm -rf ".$dir;
- echo $command;
- echo exec($command);
- }
- @header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
- @header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
- @header('Cache-Control: no-store, no-cache, must-revalidate');
- @header('Cache-Control: post-check=0, pre-check=0', false);
- @header('Pragma: no-cache');
- ?>