Mercurial > epgrec.yaz
diff getepg.php @ 112:b3ba2658a228
merged with upstream
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 13 Mar 2010 18:27:33 +0900 |
parents | 057ca53de6ca 3bed74eca373 |
children | 4afd353b4507 |
line wrap: on
line diff
--- a/getepg.php Fri Mar 12 15:32:27 2010 +0900 +++ b/getepg.php Sat Mar 13 18:27:33 2010 +0900 @@ -1,17 +1,19 @@ #!/usr/bin/php <?php - include_once('config.php'); + $script_path = dirname( __FILE__ ); + chdir( $script_path ); + include_once( $script_path . '/config.php'); include_once( INSTALL_PATH . '/DBRecord.class.php' ); include_once( INSTALL_PATH . '/Reservation.class.php' ); include_once( INSTALL_PATH . '/Keyword.class.php' ); include_once( INSTALL_PATH . '/Settings.class.php' ); + include_once( INSTALL_PATH . '/storeProgram.inc.php' ); // 後方互換性 if( ! defined( "BS_EPG_CHANNEL" ) ) define( "BS_EPG_CHANNEL", "211" ); if( ! defined( "CS1_EPG_CHANNEL" ) ) define( "CS1_EPG_CHANNEL", "CS8" ); if( ! defined( "CS2_EPG_CHANNEL" ) ) define( "CS2_EPG_CHANNEL", "CS24" ); - function check_file( $file ) { // ファイルがないなら無問題 if( ! file_exists( $file ) ) return true; @@ -25,6 +27,11 @@ return false; } + // 並列化が可能か執念深く調べる + $use_para = false; + $use_para = (function_exists( "pcntl_fork" ) && function_exists( "posix_setsid" ) && function_exists( "pcntl_signal" ) && function_exists("pcntl_setpriority")); + + $settings = Settings::factory(); $temp_xml_bs = $settings->temp_xml."_bs"; @@ -43,8 +50,14 @@ exec( $cmdline ); $cmdline = $settings->epgdump." /BS ".$settings->temp_data." ".$temp_xml_bs; exec( $cmdline ); - $cmdline = INSTALL_PATH."/storeProgram.php BS ".$temp_xml_bs." >/dev/null 2>&1 &"; - exec( $cmdline ); + if( $use_para ) { + $cmdline = INSTALL_PATH."/storeProgram.php BS ".$temp_xml_bs." >/dev/null 2>&1 &"; + exec( $cmdline ); + } + else { + storeProgram( "BS", $temp_xml_bs ); + if( file_exists( $temp_xml_bs ) ) @unlink( $temp_xml_bs ); + } if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); } @@ -57,8 +70,14 @@ exec( $cmdline ); $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$temp_xml_cs1; exec( $cmdline ); - $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs1." >/dev/null 2>&1 &"; - exec( $cmdline ); + if( $use_para ) { + $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs1." >/dev/null 2>&1 &"; + exec( $cmdline ); + } + else { + storeProgram( "CS", $temp_xml_cs1 ); + if( file_exists( $temp_xml_cs1 ) ) @unlink( $temp_xml_cs1 ); + } if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); } $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" ); @@ -67,8 +86,14 @@ exec( $cmdline ); $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$temp_xml_cs2; exec( $cmdline ); - $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs2." >/dev/null 2>&1 &"; - exec( $cmdline ); + if( $use_para ) { + $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs2." >/dev/null 2>&1 &"; + exec( $cmdline ); + } + else { + storeProgram( "CS", $temp_xml_cs2 ); + if( file_exists( $temp_xml_cs2 ) ) @unlink( $temp_xml_cs2 ); + } if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); } } @@ -84,11 +109,22 @@ exec( $cmdline ); $cmdline = $settings->epgdump." ".$key." ".$settings->temp_data." ".$temp_xml_gr.$value.""; exec( $cmdline ); - $cmdline = INSTALL_PATH."/storeProgram.php GR ".$temp_xml_gr.$value." >/dev/null 2>&1 &"; - exec( $cmdline ); + if( $use_para ) { + $cmdline = INSTALL_PATH."/storeProgram.php GR ".$temp_xml_gr.$value." >/dev/null 2>&1 &"; + exec( $cmdline ); + } + else { + storeProgram( "GR", $temp_xml_gr.$value ); + if( file_exists( $temp_xml_gr.$value ) ) @unlink( $temp_xml_gr.$value ); + } if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); } } } + // 並列ならこれで終わりにする + if( $use_para ) exit(); + garbageClean(); // 不要プログラム削除 + doKeywordReservation(); // キーワード予約 + exit(); ?>