function daggerSignalHandler($signal) { defined('QUEUE_CTL') && QueueTaskCtl::end(1, 'signal catched'); switch ($signal) { case SIGTERM: Message::showError('Caught SIGTERM'); exit; case SIGINT: Message::showError('Caught SIGINT'); exit; } }
/** * 在firephp中捕获fatal异常,用以display_error * 不开的情况下调试网站 */ function daggerShutDown() { if (!defined('QUEUE')) { // 超时报警 $runtime = floatval(BaseModelCommon::getRunTime()); $timeout = DAGGER_TIMEOUT; if ($runtime > $timeout) { $statInfo = BaseModelCommon::getStatInfo(); BaseModelLog::sendLog(90106, "[run:{$runtime}s]" . "[db:({$statInfo['db']['count']}次{$statInfo['db']['time']}ms)]" . "[mc:({$statInfo['mc']['count']}次{$statInfo['mc']['time']}ms)]" . "[request:({$statInfo['request']['count']}次{$statInfo['request']['time']}ms)]" . "[redis:({$statInfo['redis']['count']}次{$statInfo['redis']['time']}ms)]", '', BaseModelLog::ERROR_MODEL_ID_PHP); 1 === DAGGER_DEBUG && BaseModelCommon::debug("当前脚本运行[{$runtime}],大于{$timeout}秒", 'timeout_error'); } } //xhprof if (defined('DAGGER_XHPROF_ID')) { BaseModelCommon::debug(BaseModelDebug::getXhprofUrl(), 'xhprof_url'); } // all_info的debug信息 if (1 === DAGGER_DEBUG) { $statInfo = BaseModelCommon::getStatInfo(); BaseModelCommon::debug(array(array('资源', '次数', '消耗时间(ms)'), array('sql', $statInfo['db']['count'] . ' 次', $statInfo['db']['time'] . ' ms'), array('request', $statInfo['request']['count'] . ' 次', $statInfo['request']['time'] . ' ms'), array('mc', $statInfo['mc']['count'] . ' 次', $statInfo['mc']['time'] . ' ms'), array('redis', $statInfo['redis']['count'] . ' 次', $statInfo['redis']['time'] . ' ms'), array('总运行时间', '', BaseModelCommon::getRunTime())), 'all_info'); empty(BaseModelCommon::$debugTypeFilter) || BaseModelCommon::debug('部分debug信息被隐藏,规则:' . BaseModelCommon::$debugTypeFilter, 'filter_info'); BaseModelCommon::debug(DAGGER_VERSION, 'dagger_version'); } if (!defined('QUEUE')) { // 在线调试 if (1 === DAGGER_ONLINE_DEBUG) { BaseModelCommon::sendOnlineDebug(); } ob_end_flush(); } $error = error_get_last(); if (empty($error) || !(E_ERROR & $error['type'])) { // This error code is not included in error_reporting defined('QUEUE_CTL') && QueueTaskCtl::end(0, ''); return false; } formatErrorInfo($error['type'], $error['message'], $error['file'], $error['line']); defined('QUEUE_CTL') && QueueTaskCtl::end(1, $error['message']); return true; }
private static function query($sql) { if (!self::$link) { echo date("[Y-m-d H:i:s]") . "connect db\n"; self::$link = mysql_connect(self::dbHost, self::dbUser, self::dbPass); mysql_select_db(self::dbName, self::$link); } $rs = mysql_query($sql, self::$link); if (!$rs && mysql_errno(self::$link) != 1062) { echo date("[Y-m-d H:i:s]") . "re connect db\n"; self::$link = mysql_connect(self::dbHost, self::dbUser, self::dbPass, true); mysql_select_db(self::dbName, self::$link); $rs = mysql_query($sql, self::$link); var_dump($rs); } echo date("[Y-m-d H:i:s]") . $sql . "\n"; }