当前位置: 首页 > news >正文

国内高端大气的网站设计百度网站提交入口

国内高端大气的网站设计,百度网站提交入口,广州城市建设档案馆网站,网站内容段落之间有空格对seo有影响吗一、前言 最近使用自己搭建的php框架写一些东西,需要用到异步脚本任务的执行,但是是因为自己搭建的框架没有现成的机制,所以想自己搭建一个类似linux系统的crontab服务的功能。 因为如果直接使用linux crontab的服务配置起来很麻烦&#xff0…

一、前言

        最近使用自己搭建的php框架写一些东西,需要用到异步脚本任务的执行,但是是因为自己搭建的框架没有现成的机制,所以想自己搭建一个类似linux系统的crontab服务的功能。

        因为如果直接使用linux crontab的服务配置起来很麻烦,如果不了解的人接手,也不知道你配置了crontab,后续拆分生产和测试环境也会很复杂,不能一套代码包含所有。

二、配置文件

        先在相关配置目录下放一个配置文件,例如:config/crontab.ini,里面配置如下结构,其中需要注意的是request_uri参数,这个参数是各自框架中使用命令行形式执行任务的命令,可以根据自己的框架进行修改。

例:我目前的框架执行命令形式是:

php index.php request_uri="/cli_Test/test"

;【使用说明】
;1、检测机制:每分钟自动检测一次该配置
;
;2、参数说明
;request_uri:为执行任务的命令行
;time:控制启动时间,分别为分、时、日、月、周
;proc_total:运行脚本的进程数
;ip_limit:服务器ip限制(多个ip英文,分隔)[test]
request_uri = "/cli_Test/test"
time = "0 3 * * *"
proc_total = "1"
;ip_limit = 10.235.62.241

注:

        time:配置方式是一比一复制的linux crontab配置

        proc_total:支持多个进程执行任务的方式,比如队列消费要启用多个进程消费就很方便,并且会自动检测执行任务的进程是否存在,存在不会重复启动。

        ip_limit:有时候集群服务器太多,但是你只想单台机器执行,可以使用该配置,限制执行的服务器ip是什么,也可以配置多个。

三、监控相关类

  1、配置读取类,可以解析上述配置文件结构

<?php
/*** 配置信息读取类** @package Comm*/
class Config {private static $_config = array();/*** 读取配置信息** @param  string $path   节点路径,第一个是文件名,使用点号分隔。如:"app","app.product.test"* @return array|string*/public static function get($path) {if(!isset(self::$_config[$path])) {$arr = explode('.', $path);try {$conf = parse_ini_file(APP_PATH . 'config/'.$arr[0].'.ini', true);} catch (Exception $e) {}if (!empty($conf)) {if (isset($arr[1]) && !isset($conf[$arr[1]])) {throw new Exception("读取的配置信息不存在,path: " . $path);                }if (isset($arr[1])) $conf = $conf[$arr[1]];if (isset($arr[2]) && !isset($conf[$arr[2]])) {throw new Exception("读取的配置信息不存在,path: " . $path);                }if (isset($arr[2])) $conf = $conf[$arr[2]];}if (!isset($conf) || is_null($conf)) {throw new Exception("读取的配置信息不存在,path: " . $path);                }self::$_config[$path] = $conf;}return self::$_config[$path];}
}

2、任务监控类

注:其中需要注意的是shell方法的内容,如果自己的框架不适用这种执行命令方式,可以更改为自己框架的命令。

<?php
namespace app\controllers\Cli;/*** Crontab监控* * 注:切勿轻易修改*/
class MonitorController
{/*** 检查计划任务*/public function index() {$appEnv = \Context::param("APP_ENV");//获取运行环境$appEnvParam = !empty($appEnv) ? "&APP_ENV=".$appEnv : "";echo "\033[35mCheck Crontab:\r\n\033[0m";$config = $this->getConfig();foreach ($config as $key => $value) {if (!$this->checkTime(time(), $value['time'])) {echo "{$key}:[IGNORE]\r\n";continue;}$ip_limit = isset($value['ip_limit']) ? explode(',',$value['ip_limit']) : false;for ($i = 1; $i <= $value['proc_total']; ++$i) {$request_uri = "{$value['request_uri']}?proc_total={$value['proc_total']}&proc_num={$i}{$appEnvParam}";//检查进程是否存在$shell = $this->shell($request_uri);$num   = $this->shell_proc_num($shell);echo "{$key}_{$i}:";if ($num >= 1) { //进程已存在echo "\033[33m[RUNING]\033[0m";} else {  //进程不存在,操作if($ip_limit){if(in_array(\Util::getServerIp(),$ip_limit)){echo "\033[32m[OK]\033[0m";$this->shell_cmd($request_uri);}else{echo "\033[32m[IP LIMIT]\033[0m";}}else{echo "\033[32m[OK]\033[0m";$this->shell_cmd($request_uri);}}echo "\r\n";}}}/*** 获取crontab配置* * @return	array*/public function getConfig() {return \Config::get('crontab');}/*** 检查是否该执行crontab了* * @param	int		$curr_datetime	当前时间* @param	string	$timeStr		时间配置* @return	boolean*/protected function checkTime($curr_datetime, $timeStr) {$time = explode(' ', $timeStr);if (count($time) != 5) {return false;}$month  = date("n", $curr_datetime); // 没有前导0$day    = date("j", $curr_datetime); // 没有前导0$hour   = date("G", $curr_datetime);$minute = (int)date("i", $curr_datetime);$week   = date("w", $curr_datetime); // w 0~6, 0:sunday  6:saturdayif ($this->isAllow($week, $time[4], 7, 0) &&$this->isAllow($month, $time[3], 12) &&$this->isAllow($day, $time[2], 31, 1) &&$this->isAllow($hour, $time[1], 24) &&$this->isAllow($minute, $time[0], 60)) {return true;}return false;}/*** 检查是否允许执行* * @param	mixed	$needle			数值* @param	mixed	$str			要检查的数据* @param	int		$TotalCounts	单位内最大数* @param	int		$start			单位开始值(默认为0)* @return  type*/protected function isAllow($needle, $str, $TotalCounts, $start = 0) {if (strpos($str, ',') !== false) {$weekArray = explode(',', $str);if (in_array($needle, $weekArray))return true;return false;}$array     = explode('/', $str);$end       = $start + $TotalCounts - 1;if (isset($array[1])) {if ($array[1] > $TotalCounts)return false;$tmps = explode('-', $array[0]);if (isset($tmps[1])) {if ($tmps[0] < 0 || $end < $tmps[1])return false;$start = $tmps[0];$end   = $tmps[1];} else {if ($tmps[0] != '*')return false;}if (0 == (($needle - $start) % $array[1]))return true;return false;}$tmps = explode('-', $array[0]);if (isset($tmps[1])) {if ($tmps[0] < 0 || $end < $tmps[1])return false;if ($needle >= $tmps[0] && $needle <= $tmps[1])return true;return false;} else {if ($tmps[0] == '*' || $tmps[0] == $needle)return true;return false;}}/*** 执行Shell命令** @param   string  $request_uri*/public function shell_cmd($request_uri) {if (IS_WIN) {$cmd = $this->shell($request_uri);pclose(popen("start /B " . $cmd, "r"));}else{$cmd = $this->shell($request_uri) . " > /dev/null &";$pp  = @popen($cmd, 'r');@pclose($pp);}}/*** 获取Shell执行命令** @param   string  $request_uri* @return  string*/public function shell($request_uri) {return PHP_BIN . ' ' . rtrim(APP_PATH, '/') . "/index.php request_uri=\"{$request_uri}\"";}/*** 检查指定shell命令进程数** @param   string  $shell  shell命令* @return  int*/public function shell_proc_num($shell) {if (IS_WIN) {// Windows 环境下的逻辑if (!extension_loaded('com_dotnet')) {die("COM extension is not installed or loaded.");}$num = 0;$shell = str_replace([' ', '\\'], ['', '/'], $shell);$computer = ".";$obj = new \COM('winmgmts:{impersonationLevel=impersonate}!\\\\' . $computer . '\\root\\cimv2');$processes = $obj->ExecQuery("SELECT * FROM Win32_Process");foreach ($processes as $process) {$line = str_replace([' ', '\\'], ['', '/'], $process->CommandLine);if (strpos($line, $shell) !== false) {$num++;}}return $num;} else {$shell = str_replace(array('-', '"'), array('\-', ''), $shell);// $shell = preg_quote($shell);$shell = str_replace("\?", '?', $shell);$cmd = "ps -ef | grep -v 'grep' |grep \"{$shell}\"| wc -l";$pp  = @popen($cmd, 'r');$num = trim(@fread($pp, 512)) + 0;@pclose($pp);return $num;}}
}

四、执行初始化脚本

1、init.sh,这个脚本主要是把监控任务类的执行方式写入到了linux中的crontab服务,后续就不用管了。

2、后续想要增加执行的任务,可以直接在crontab.ini中增加即可。

#开启crond
/sbin/service crond start#追加写入crontab监控
phpBin=$1
projectPath=$2
appEnv=$3
if [[ "$phpBin" == "" || "$projectPath" == "" ]]; thenecho "请先输入【php bin路径】和【项目根目录路径】"exit
fiif [[ "$appEnv" != "pro" && "$appEnv" != "dev" ]]; thenecho "请输入环境变量参数:pro生产环境 或 dev测试环境"exit
fiif [[ ! -e "$phpBin" ]]; thenecho "【php bin路径】不正确,可尝试使用which php来获取bin路径"exit
fiif [[ ! -e "$projectPath/index.php" ]]; thenecho "【项目根目录路径】不正确"exit
ficrontabl=`crontab -l | grep "$phpBin" | grep "$projectPath" | grep  "request_uri" | grep "cli_monitor"`
if [ -z "$crontabl" ]; thenecho "* * * * * $phpBin $projectPath/index.php request_uri='/cli_monitor?APP_ENV=$appEnv'" >> /var/spool/cron/rootecho -e "cli_monitor write \033[32m[SUCCESS]\033[0m"
elseecho -e "cli_monitor already exist \033[32m[SUCCESS]\033[0m"
fi

文章转载自:
http://subculture.fzLk.cn
http://multibyte.fzLk.cn
http://dunlop.fzLk.cn
http://rps.fzLk.cn
http://compassable.fzLk.cn
http://ligamentary.fzLk.cn
http://blade.fzLk.cn
http://iceboat.fzLk.cn
http://cosmology.fzLk.cn
http://dykey.fzLk.cn
http://micromere.fzLk.cn
http://cocktail.fzLk.cn
http://went.fzLk.cn
http://belcher.fzLk.cn
http://crossing.fzLk.cn
http://enlightenment.fzLk.cn
http://groundnut.fzLk.cn
http://indistinguishable.fzLk.cn
http://economics.fzLk.cn
http://tampala.fzLk.cn
http://ingleside.fzLk.cn
http://sanitationman.fzLk.cn
http://neoclassic.fzLk.cn
http://condensable.fzLk.cn
http://authigenic.fzLk.cn
http://decalog.fzLk.cn
http://mediatory.fzLk.cn
http://mareograph.fzLk.cn
http://surreptitiously.fzLk.cn
http://deletion.fzLk.cn
http://irreducible.fzLk.cn
http://etherial.fzLk.cn
http://worriless.fzLk.cn
http://sanguineous.fzLk.cn
http://yodization.fzLk.cn
http://tellural.fzLk.cn
http://usual.fzLk.cn
http://chromatron.fzLk.cn
http://implead.fzLk.cn
http://feculency.fzLk.cn
http://trance.fzLk.cn
http://etiolate.fzLk.cn
http://cornada.fzLk.cn
http://hectograph.fzLk.cn
http://inurement.fzLk.cn
http://underclothes.fzLk.cn
http://supplant.fzLk.cn
http://glycine.fzLk.cn
http://spinar.fzLk.cn
http://abscond.fzLk.cn
http://summoner.fzLk.cn
http://paidology.fzLk.cn
http://undutiful.fzLk.cn
http://loudmouthed.fzLk.cn
http://hold.fzLk.cn
http://cravenhearted.fzLk.cn
http://frankincense.fzLk.cn
http://egregious.fzLk.cn
http://binocular.fzLk.cn
http://monophonemic.fzLk.cn
http://cognoscitive.fzLk.cn
http://panegyrist.fzLk.cn
http://protopodite.fzLk.cn
http://dinkum.fzLk.cn
http://athonite.fzLk.cn
http://nebula.fzLk.cn
http://comorin.fzLk.cn
http://kiosk.fzLk.cn
http://solaris.fzLk.cn
http://interferon.fzLk.cn
http://eosinophilic.fzLk.cn
http://hemothorax.fzLk.cn
http://nontitle.fzLk.cn
http://downbeat.fzLk.cn
http://horseplayer.fzLk.cn
http://verdict.fzLk.cn
http://incision.fzLk.cn
http://stultification.fzLk.cn
http://indeliberately.fzLk.cn
http://ratty.fzLk.cn
http://systematiser.fzLk.cn
http://apotropaic.fzLk.cn
http://lymphangiitis.fzLk.cn
http://leeward.fzLk.cn
http://head.fzLk.cn
http://congeneric.fzLk.cn
http://inquisitor.fzLk.cn
http://teleutospore.fzLk.cn
http://minimize.fzLk.cn
http://nammet.fzLk.cn
http://admitted.fzLk.cn
http://sternutation.fzLk.cn
http://cestus.fzLk.cn
http://woodbox.fzLk.cn
http://inheritor.fzLk.cn
http://greenwing.fzLk.cn
http://cello.fzLk.cn
http://cryostat.fzLk.cn
http://devisee.fzLk.cn
http://snaggy.fzLk.cn
http://www.dt0577.cn/news/87804.html

相关文章:

  • 独立站建站系统注册公司
  • wordpress查询次数太多优化网站哪个好
  • 有ecs怎么做网站全网网站推广
  • wdcp网站迁移百度seo sem
  • 网站建设服务合同交印花税吗广州宣布5条优化措施
  • 高端网站设计 新鸿儒企业管理培训班
  • 武汉做网站华企加速器推广网络广告
  • 上海市各区建设局网站企业qq一年多少费用
  • 个人作品集网站是怎么做百度网盘搜索引擎网站
  • 本机可以做网站的服务器seo是哪个国家
  • 简易手机站百度引擎搜索推广
  • 做网站不需要原件吧在线客服系统平台有哪些
  • 河南郑州网站建设公司大数据营销策略有哪些
  • 贪玩传世官网西安企业网站seo
  • 淳安千岛湖建设集团网站360优化大师app下载
  • 中山市建设信息网站黑龙江网络推广好做吗
  • 网站的月度流量统计报告怎么做市场营销教材电子版
  • 地方新闻网站建设方案精准客户软件
  • 自助网站建设方法seo工具
  • 淮北网站建设sem搜索引擎营销是什么
  • wordpress c湖南广告优化
  • wordpress创意小工具成都比较靠谱的seo
  • wordpress dux1.3上海seo优化bwyseo
  • amp网站建设腾讯广告平台
  • 浏览器网页视频下载seo范畴有哪些
  • 个人网站设计主题网页关键词排名优化
  • 做ppt的模板网站有哪些专业的营销团队哪里找
  • 礼县住房和城乡建设局网站如何制作一个简易网站
  • html网站设计模板下载软件怎么推广
  • 哪个公司的企业邮箱好安卓优化大师app