《百度MIP版本鍊接的批量提交》中獲取、整理URL是靠手工進行,設置crontab定時文件也是用手工編輯,這兩項都很費時。昨天把第一項工作用程序實現了,詳見《從XML網站地圖中獲取純URL網址的PHP程序》,今天幹脆把第二項工作也用程序來生成。
直接貼PHP程序代碼:
<?php /* * create cron file for submit mip urls to baidu * jamesqi 2017-8-31 * */ // please set below: $start_month = 8; $start_day = 31; $start_hour = 22; $start_minute = 00; $next_time_minute = 5; $php_script = '/alidata/server/php/bin/php'; //$submit_php_file = '/root/mip/submit_mip.php';//for Drupal $submit_php_file = '/root/mip/submit_subdomain.php';//for MediaWiki $submit_domain = "cn.mip.youbianku.com"; $submit_url_file = "/root/mip/cn.mip.youbianku.com.url.txt"; //$output_cron_file_name = "/root/mip/mip.$site.mingluji.com.cron.txt";//for test $output_cron_file_name = "/etc/cron.d/cn.mip.youbianku.com.cron.txt";//for set cron // please set above // do not change below ini_set('memory_limit', '1024M'); print "programe start\n"; print "start_month = $start_month\n"; print "start_day = $start_day\n"; print "start_hour = $start_hour\n"; print "start_minute = $start_minute\n"; print "next_time_minute = $next_time_minute\n"; print "php_script = $php_script\n"; print "submit_php_file = $submit_php_file\n"; print "submit_domain = $submit_domain\n"; print "submit_url_file = $submit_url_file\n"; print "output_cron_file_name = $output_cron_file_name\n"; $submit_url_file_content = file_get_contents($submit_url_file); $submit_url_file_line_count = substr_count($submit_url_file_content,"\n"); print "submit_url_file_line_count = $submit_url_file_line_count lines\n"; $submit_times = ceil($submit_url_file_line_count / 2000); $submit_days = ceil($submit_url_file_line_count / 10000); $submit_count = 0; $output = ''; $submit_month = $start_month; $submit_day = $start_day; for ($day_count=1; $day_count<=$submit_days; $day_count++) { $output .= "\n# day_count = $day_count : submit_month = $submit_month, submit_day = $submit_day\n\n"; $submit_minute = $start_minute; $submit_hour = $start_hour; for ($i=1; $i<=5; $i++) { $submit_count++; if ($submit_count > $submit_times) break; $count_start = ($submit_count - 1) * 2000 + 1; $output .= "$submit_minute $submit_hour $submit_day $submit_month * root $php_script $submit_php_file $submit_domain $submit_url_file $count_start 2000\n"; $submit_minute = $submit_minute + $next_time_minute; if ($submit_minute >= 60) { $submit_minute = $submit_minute - 60; $submit_hour++; } } if ($submit_month == 1 && $submit_day == 31) { $submit_month = 2; $submit_day = 1; } elseif ($submit_month == 2 && $submit_day == 28) { $submit_month = 3; $submit_day = 1; } elseif ($submit_month == 3 && $submit_day == 31) { $submit_month = 4; $submit_day = 1; } elseif ($submit_month == 4 && $submit_day == 30) { $submit_month = 5; $submit_day = 1; } elseif ($submit_month == 5 && $submit_day == 31) { $submit_month = 6; $submit_day = 1; } elseif ($submit_month == 6 && $submit_day == 30) { $submit_month = 7; $submit_day = 1; } elseif ($submit_month == 7 && $submit_day == 31) { $submit_month = 8; $submit_day = 1; } elseif ($submit_month == 8 && $submit_day == 31) { $submit_month = 9; $submit_day = 1; } elseif ($submit_month == 9 && $submit_day == 30) { $submit_month = 10; $submit_day = 1; } elseif ($submit_month == 10 && $submit_day == 31) { $submit_month = 11; $submit_day = 1; } elseif ($submit_month == 11 && $submit_day == 30) { $submit_month = 12; $submit_day = 1; } elseif ($submit_month == 12 && $submit_day == 31) { $submit_month = 1; $submit_day = 1; } else { $submit_day++; } } print "output = $output\n"; $output_cron_file = fopen("$output_cron_file_name", "w") or die("Unable to open file!"); fwrite($output_cron_file, $output); fclose($output_cron_file); print "please check the output file: $output_cron_file_name\n"; print "programe end\n"; ?>
生成的文件類似這樣:
# day_count = 1 : submit_month = 8, submit_day = 31 0 21 31 8 * root /alidata/server/php/bin/php /root/mip/submit_subdomain.php mip.xizang.mingluji.com /root/mip/mip.xizang.mingluji.com.url.txt 1 2000 5 21 31 8 * root /alidata/server/php/bin/php /root/mip/submit_subdomain.php mip.xizang.mingluji.com /root/mip/mip.xizang.mingluji.com.url.txt 2001 2000 10 21 31 8 * root /alidata/server/php/bin/php /root/mip/submit_subdomain.php mip.xizang.mingluji.com /root/mip/mip.xizang.mingluji.com.url.txt 4001 2000 15 21 31 8 * root /alidata/server/php/bin/php /root/mip/submit_subdomain.php mip.xizang.mingluji.com /root/mip/mip.xizang.mingluji.com.url.txt 6001 2000 20 21 31 8 * root /alidata/server/php/bin/php /root/mip/submit_subdomain.php mip.xizang.mingluji.com /root/mip/mip.xizang.mingluji.com.url.txt 8001 2000 # day_count = 2 : submit_month = 9, submit_day = 1 0 21 1 9 * root /alidata/server/php/bin/php /root/mip/submit_subdomain.php mip.xizang.mingluji.com /root/mip/mip.xizang.mingluji.com.url.txt 10001 2000
當數據量大的時候,這樣方便了許多。
评论