diff --git a/framework/base/router.class.php b/framework/base/router.class.php index 15b02574ca..b4e9fdf481 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -1891,23 +1891,37 @@ class baseRouter $defaultParams[$name] = $default; } - /** - * 根据PATH_INFO或者GET方式设置请求的参数。 - * Set params according PATH_INFO or GET. - */ - if($this->config->requestType != 'GET') + if ('cli' === PHP_SAPI) { - $this->setParamsByPathInfo($defaultParams); + if ($this->params) + { + $this->params = array_merge($defaultParams, $this->params); + } + else + { + $this->params = $defaultParams; + } } else { - $this->setParamsByGET($defaultParams); - } + /** + * 根据PATH_INFO或者GET方式设置请求的参数。 + * Set params according PATH_INFO or GET. + */ + if($this->config->requestType != 'GET') + { + $this->setParamsByPathInfo($defaultParams); + } + else + { + $this->setParamsByGET($defaultParams); + } - if($this->config->framework->filterParam == 2) - { - $_GET = validater::filterParam($_GET, 'get'); - $_COOKIE = validater::filterParam($_COOKIE, 'cookie'); + if($this->config->framework->filterParam == 2) + { + $_GET = validater::filterParam($_GET, 'get'); + $_COOKIE = validater::filterParam($_COOKIE, 'cookie'); + } } /* 调用该方法 Call the method. */ diff --git a/module/cron/control.php b/module/cron/control.php index 2486ba3f3f..ca2bfd7f84 100644 --- a/module/cron/control.php +++ b/module/cron/control.php @@ -134,9 +134,12 @@ class cron extends control */ public function ajaxExec($restart = false) { - ignore_user_abort(true); - set_time_limit(0); - session_write_close(); + if ('cli' !== PHP_SAPI) + { + ignore_user_abort(true); + set_time_limit(0); + session_write_close(); + } /* Check cron turnon. */ if(empty($this->config->global->cron)) die(); @@ -183,11 +186,21 @@ class cron extends control /* Skip cron that status is running and run time is less than max. */ if($cronInfo->status == 'running' and (time() - strtotime($cronInfo->lastTime)) < $this->config->cron->maxRunTime) continue; /* Skip cron that last time is more than this cron time. */ - if($cronInfo->lastTime > $cron['time']->format(DT_DATETIME1)) die(); + if ('cli' === PHP_SAPI) + { + if($cronInfo->lastTime >= $cron['time']->format(DT_DATETIME1)) continue; + } + else + { + if($cronInfo->lastTime > $cron['time']->format(DT_DATETIME1)) die(); + } if($now > $cron['time']) { - $this->cron->changeStatus($id, 'running'); + if (!$this->cron->changeStatusRunning($id, $cronInfo->lastTime)) + { + continue; + } $parsedCrons[$id]['time'] = $cron['cron']->getNextRunDate(); /* Execution command. */ @@ -239,11 +252,12 @@ class cron extends control sleep($sleepTime); /* Break while. */ - if(connection_status() != CONNECTION_NORMAL) break; + if('cli' !== PHP_SAPI && connection_status() != CONNECTION_NORMAL) break; if(((time() - $startedTime) / 3600 / 24) >= $this->config->cron->maxRunDays) break; } /* Revert cron status to stop. */ $this->cron->markCronStatus('stop', $configID); } + } diff --git a/module/cron/model.php b/module/cron/model.php index ab9822d8fc..e857b4dcca 100644 --- a/module/cron/model.php +++ b/module/cron/model.php @@ -94,6 +94,27 @@ class cronModel extends model return dao::isError() ? false : true; } + /** + * Change cron status to running + * + * @param int $cronID + * @param string $lastTime + * @access public + * @return bool|int + */ + public function changeStatusRunning($cronID, $lastTime) + { + $data = new stdclass(); + $data->status = 'running'; + $data->lastTime = date(DT_DATETIME1); + $rows = $this->dao->update(TABLE_CRON)->data($data) + ->where('id')->eq($cronID) + ->andWhere('status')->ne('running') + ->andWhere('lastTime')->eq($lastTime) + ->exec(); + return dao::isError() ? false : $rows; + } + /** * Log cron. * diff --git a/roadrunner/.rr.yaml b/roadrunner/.rr.yaml new file mode 100644 index 0000000000..e98c8a112c --- /dev/null +++ b/roadrunner/.rr.yaml @@ -0,0 +1,7 @@ +service: + cron: + command: php cron-worker.php + process_num: 4 + exec_timeout: 0 + remain_after_exit: true + restart_sec: 1 diff --git a/roadrunner/README.md b/roadrunner/README.md new file mode 100644 index 0000000000..741026a58a --- /dev/null +++ b/roadrunner/README.md @@ -0,0 +1,13 @@ +# 说明 + +## 环境安装 + +安装 RoadRunner: + +Composer: `composer update` + +## 启动服务 + +```shell +rr serve +``` diff --git a/roadrunner/composer.json b/roadrunner/composer.json new file mode 100644 index 0000000000..67092734e8 --- /dev/null +++ b/roadrunner/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "spiral/roadrunner": "^2.6", + "nyholm/psr7": "^1.4" + } +} diff --git a/roadrunner/cron-worker.php b/roadrunner/cron-worker.php new file mode 100644 index 0000000000..f58bdd732e --- /dev/null +++ b/roadrunner/cron-worker.php @@ -0,0 +1,35 @@ + + * @package ZenTaoPMS + * @version $Id: index.php 5036 2013-07-06 05:26:44Z wyd621@gmail.com $ + * @link http://www.zentao.net + */ +/* Set the error reporting. */ +error_reporting(0); + +/* Load the framework. */ +include '../framework/router.class.php'; +include '../framework/control.class.php'; +include '../framework/model.class.php'; +include '../framework/helper.class.php'; + +/* Log the time and define the run mode. */ +$startTime = getTime(); + +/* Instance the app. */ +$app = router::createApp('pms', dirname(__DIR__), 'router'); + +/* Run the app. */ +$common = $app->loadCommon(); + +$app->moduleName = 'cron'; +$app->methodName = 'ajaxExec'; +$app->setControlFile(); +$app->loadModule();