/** * * @param \Yaf_Dispatcher $dispatcher * @param string $jqueryVer 使用的jquery文件,默认值:jquery-1.11.2.min.js * @return view */ public static function initYafBySooh($dispatcher, $jqueryVer = 'jquery-1.11.2.min.js') { $router = $dispatcher->getRouter(); $router->addRoute("byVar", new \Yaf_Route_Supervar(SOOH_ROUTE_VAR)); \Yaf_Loader::getInstance()->registerLocalNameSpace($GLOBALS['CONF']['localLibs']); $req = $dispatcher->getRequest(); $tmp = $req->get('__ONLY__'); if ($tmp == 'body') { \SoohYaf\Viewext::$bodyonly = true; } $tmp = trim($req->get('__VIEW__')); //html(default),wap, json define('VIW_INC_PATH', APP_PATH . '/application/views/_inc/'); \SoohYaf\Viewext::$jqueryVer = $jqueryVer; if (!empty($tmp)) { $tmp = strtolower($tmp); \Sooh\Base\Ini::getInstance()->viewRenderType($tmp); if ($tmp == 'jsonp') { \Sooh\Base\Ini::getInstance()->initGobal(array('nameJsonP' => $req->get('jsonp', 'jsonp'))); } } // $tmp = $dispatcher->getRequest()->get('__GZIP__'); // if(!empty($tmp)){ // $tmp = strtolower ($tmp); // if($tmp=='gzip')define("ZIP_OUTPUT",$tmp); // } $view = new \SoohYaf\Viewext(null); $dispatcher->setView($view); $dispatcher->registerPlugin(new SoohPlugin()); return $view; }
public function errorAction($exception) { $ini = \Sooh\Base\Ini::getInstance(); $render = $ini->viewRenderType(); switch ($render) { case "json": header('Content-type: application/json'); break; case 'jsonp': break; default: $ini->viewRenderType('json'); header('Content-type: application/json'); break; } if (is_a($exception, '\\Sooh\\DB\\Acl\\ErrNeedsLogin')) { \Sooh\Base\Log\Data::getInstance()->ret = 'needs login'; // }elseif(is_a($exception,'\Prj\ErrCode')){ // $this->_view->assign('code',$exception->getCode()); // $this->_view->assign('msg',$exception->getMessage()); // \Sooh\Base\Log\Data::getInstance()->ret = $exception->getMessage(); // }elseif(is_a($exception,'\Prj\RetCode')){ // $this->_view->assign('code',200); // $this->_view->assign('msg',$exception->getMessage()); } else { var_log($exception); $this->_view->assign('code', $exception->getCode()); $this->_view->assign('msg', $exception->getMessage()); \Sooh\Base\Log\Data::getInstance()->ret = $exception->getMessage(); } }
protected function newLogId($plan = 'c') { $dt = microtime(true); list($s, $ms) = explode('.', $dt); $s = $s - 1435680000; //18446744073709551616 //17------------------ 18组服务器 //--1234567890-------- 时间戳 //------------sss----- 毫秒 //---------------12345 进程 switch ($plan) { case 'a': //plan-a 180组服务器,30几年后溢出,(每个请求需要一个进程处理至少1个毫秒,) $this->plan = 'a'; return sprintf("%03d%09d%03d%05d", \Sooh\Base\Ini::getInstance()->get('ServerId', 0), $s, substr($ms, 0, 3), getmypid()); case 'b': //plan-b 18组服务器, 300年后溢出, (每个请求需要一个进程处理至少1个毫秒,) $this->plan = 'b'; return sprintf("%02d%010d%03d%05d", \Sooh\Base\Ini::getInstance()->get('ServerId', 0), $s, substr($ms, 0, 3), getmypid()); case 'c': //plan-c 18组服务器, 30年后溢出, (每个请求需要一个进程处理至少0.1个毫秒,) $this->plan = 'c'; return sprintf("%02d%09d%04d%05d", \Sooh\Base\Ini::getInstance()->get('ServerId', 0), $s, substr($ms, 0, 4), getmypid()); default: throw new \Sooh\Base\ErrException('unknown support log-guid-generate'); } }
/** * 测试用 */ public function resetdayAction() { if (\Sooh\Base\Ini::getInstance()->get('deploymentCode') < 40) { $this->book->doDebugReset($this->_request->get('ymd') - 0, $this->_request->get('num', -1) - 0, $this->userOrAccountId); $this->_view->assign('userIdentifier', $this->user->getAccountId()); $this->_view->assign('now', date('Ymd H:i:s')); } }
protected static function numToSplit() { if (\Sooh\Base\Ini::getInstance()->get('deploymentCode') <= 20) { return 1; } else { return 1; } }
/** * get session id * @return string */ public static function getSessId() { if (empty($_COOKIE[self::SessionIdName])) { $_COOKIE[self::SessionIdName] = md5(microtime(true) . \Sooh\Base\Tools::remoteIP()); $cookieDomain = \Sooh\Base\Ini::getInstance()->cookieDomain(); setcookie(self::SessionIdName, $_COOKIE[self::SessionIdName], time() + 315360000, '/', $cookieDomain); } return $_COOKIE[self::SessionIdName]; }
/** * 检查,必须是通过crond.php执行的 */ public function init() { $this->ini = \Sooh\Base\Ini::getInstance(); if ($this->ini->get('released')) { if (SOOH_INDEX_FILE !== 'crond.php') { die('not start with crond'); } } }
public function fetchini($service) { if ($this->rpc === null) { $ini = \Sooh\Base\Ini::getInstance()->get('RpcConfig'); unset($ini['force']); return $ini; } else { \Sooh\Base\Log\Data::error('Rpcservices should never be called by rpc'); throw new \Sooh\Base\ErrException('Rpcservices should never be called by rpc'); //return $this->rpc->initArgs(array('arg1'=>$arg1))->send();//call('CheckinBook/'.__FUNCTION__, array($withBonus,$userOrAccountId)); } }
protected function fixTplPath($strTpl) { $renderType = \Sooh\Base\Ini::getInstance()->viewRenderType(); switch ($renderType) { case 'html': return str_replace('.phtml', '.www.phtml', $strTpl); case 'wap': return str_replace('.phtml', '.wap.phtml', $strTpl); case 'echo': return; case 'json': return; } }
/** * 获取PRC配置参数 * @param string $serviceName * @return array array(key=>sss,urls=>array(),protocol=>默认HttpGet) * @throws \Sooh\Base\ErrException */ public static function getRpcIni($serviceName) { if (self::$_rpcServices !== null) { return self::$_rpcServices->fetchini($serviceName); } $ini = \Sooh\Base\Ini::getInstance(); if (empty(self::$_instances['_RPC_ROUTE_'])) { self::$_instances['_RPC_ROUTE_'] = new Broker(); self::$_instances['_RPC_ROUTE_']->final_service = 'rpcservices'; //self::$_instances['_RPC_ROUTE_']->final_cmd='fetchini'; self::$_instances['_RPC_ROUTE_']->final_protocol = $ini->get('RpcConfig.protocol'); self::$_instances['_RPC_ROUTE_']->final_key = $ini->get('RpcConfig.key'); self::$_instances['_RPC_ROUTE_']->final_hosts = $ini->get('RpcConfig.urls'); } return self::$_instances['_RPC_ROUTE_']->initArgs(array('service' => $serviceName))->send('fetchini'); }
public function indexAction() { \Lib\Services\SessionStorage::setStorageIni(); \Sooh\Base\Session\Data::getInstance(\Lib\Services\SessionStorage::getInstance($this->getRpcDefault('SessionStorage'))); \Sooh\Base\Ini::getInstance()->viewRenderType('json'); $this->_view->assign('normal', true); $this->_view->assign('sessionId', \Sooh\Base\Session\Data::getSessId()); $this->_view->assign('accountId', \Sooh\Base\Session\Data::getInstance()->get('accountId')); $today = \Sooh\Base\Time::getInstance()->YmdFull; $uri0 = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '' . $_SERVER["SCRIPT_NAME"]; $this->_view->assign('urls', array('login' => $uri0 . '?__=passport/login&loginname=qq01&passwd=123456', 'register' => $uri0 . '?__=passport/register&loginname=qq01&passwd=123456&contractId=34562342523534', 'checkin-checkin' => $uri0 . '?__=checkin/checkin&with_bonus=1', 'checkin-today' => $uri0 . '?__=checkin/today&with_bonus=1', 'checkin-reset' => $uri0 . '?__=checkin/resetday&ymd=' . $today, 'checkin-resetAll' => $uri0 . '?__=checkin/resetday&ymd=' . $today . '&num=0')); //$this->_view->assign('code1',\Lib\Subdir\Abc::run()); throw new \ErrorException('msg append by exception'); //$this->_view->assign('code2', \Subdir\Test::run()); //$this->_view->assign('code3',\Subdir_Type1::run()); }
public function init() { $this->ini = \Sooh\Base\Ini::getInstance(); if ($this->_request->isPost()) { $this->onInit_chkMaintainTime(); } list($deviceId, $uid) = $this->initSession(); \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\TextAll(), 'trace'); \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\TextAll(), 'error'); \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\Database('dbgrpForLog', 2), 'evt'); $log = \Sooh\Base\Log\Data::getInstance('c'); $log->clientType = 0; $log->deviceId = $deviceId; $log->contractId = '0'; $log->evt = $this->_request->getModuleName() . '/' . $this->_request->getControllerName() . '/' . $this->_request->getActionName(); $log->isLogined = 0; $log->userId = $uid; }
protected function setUpReal($driver) { $this->driver = $driver; $lines = file(__DIR__ . '/../sqls/connect.ini'); foreach ($lines as $line) { $tmp = explode('=', $line); if ($tmp[0] == $driver) { array_shift($tmp); $tmp = json_decode(implode('=', $tmp), true); $ini = \Sooh\Base\Ini::getInstance(); $old = $ini->get('dbConf'); $old[$this->driver] = $tmp; $ini->initGobal(array('dbConf' => $old)); $this->dbDefault = $tmp['dbEnums']['default'] . '.'; break; } } $this->getDB()->delRecords('tb_0', array('autoid' => 100)); }
protected function setUpReal($driver) { $ini = \Sooh\Base\Ini::getInstance(); $old = $ini->get('dbConf'); $this->driver = $driver; $db_0 = $driver . '0'; $db_1 = $driver . '1'; $lines = file(__DIR__ . '/../sqls/connect.ini'); foreach ($lines as $line) { $tmp = explode('=', $line); if ($tmp[0] == $db_0 || $db_1 == $tmp[0]) { $id = array_shift($tmp); $tmp = json_decode(implode('=', $tmp), true); $old[$id] = $tmp; } } $ini->initGobal(array('dbConf' => $old)); $old = $ini->get('dbByObj'); $old['TstKVObj'] = array($db_0, $db_1); $ini->initGobal(array('dbByObj' => $old)); $this->getDB($db_1)->delRecords('tb_1', array('autoid' => 99)); }
/** * 设置主键 * @param array $pkey * @return \Sooh\DB\Base\KVObjV2 */ protected function initPkey($pkey) { $this->pkey = $pkey; $this->pkey_val = $this->calcPkey($pkey); $ini = \Sooh\Base\Ini::getInstance(); $tmp = $ini->get('dbByObj.' . $this->objIdentifier); if (!is_array($tmp)) { $tmp = $ini->get('dbByObj.default'); if (!is_array($tmp)) { $tmp = [1, 'default']; } } $this->initdb($ini, $tmp, 0); $tmp = $ini->get('dbByObj.' . $this->objIdentifier . 'Cache'); if (!is_array($tmp)) { $tmp = $ini->get('dbByObj.defaultCache'); if (!is_array($tmp)) { $tmp = [1, 'default']; } } $this->initdb($ini, $tmp, 1); return $this; }
protected function onLogin($accountInfo) { $sess = \Sooh\Base\Session\Data::getInstance(); $sess->set('accountId', $accountInfo['accountId']); $sess->set('nickname', $accountInfo['nickname']); $this->_view->assign('account', array('accountId' => $accountInfo['accountId'], 'nickname' => $accountInfo['nickname'])); /** $userOrAccountId = $this->user; $checkinBook = \Lib\Services\CheckinBook::getInstance(); */ $userOrAccountId = $accountInfo['accountId']; $checkinBook = \Lib\Services\CheckinBook::getInstance($this->getRpcDefault('CheckinBook')); $this->_view->assign('checkinBook', $checkinBook->doGetTodayStatus(1, $userOrAccountId)['data']); $this->_view->assign('shopPoints', array('nleft' => 'todo', 'history' => array('todo'))); $user = \Prj\Data\User::getCopy($userOrAccountId); setcookie('nickname', $accountInfo['nickname'], 0, '/', \Sooh\Base\Ini::getInstance()->cookieDomain()); $user->load(); $dt = \Sooh\Base\Time::getInstance(); if ($user->exists() === false) { $user->setField('nickname', $accountInfo['nickname']); $user->setField('contractId', $accountInfo['contractId']); $user->setField('regYmd', $dt->YmdFull); $user->setField('regHHiiss', $dt->his); $user->setField('regClient', self::tmp_clientType); $user->setField('regIP', \Sooh\Base\Tools::remoteIP()); //$user->setField(self::fieldUser, array()); $user->update(); } else { $user->setField('nickname', $accountInfo['nickname']); $user->setField('lastDt', $dt->timestamp()); $user->setField('lastIP', \Sooh\Base\Tools::remoteIP()); $user->update(); } $sess->shutdown(); $this->returnOK(); }
protected function checkSign($service, $appKey = null) { $dt = $this->_request->get('dt'); $sign = $this->_request->get('sign'); if ($appKey === null) { $arr = \Sooh\Base\Rpc\Broker::getRpcIni($service); $appKey = $arr['key']; } if (\Sooh\Base\Ini::getInstance()->get('released')) { $dur = abs($dt - time()); if ($dur > 60) { $this->error('sign error'); return false; } if ($sign != md5($dt . $appKey)) { $this->error('sign error'); return false; } } else { if (empty($sign)) { error_log('trace:sign of serviceCtrl skipped'); } elseif ($sign != md5($dt . $appKey)) { $this->error('sign error'); return false; } } return true; }
public static function runBackground($strArgs) { $ini = \Sooh\Base\Ini::getInstance(); if (DIRECTORY_SEPARATOR == '/') { //unix $cmd = $ini->get('path_php') . ' ' . $ini->get('path_console') . " \"{$strArgs}\" &"; } else { //win $cmd = 'start /b ' . $ini->get('path_php') . ' ' . $ini->get('path_console') . " \"{$strArgs}\""; } pclose(popen($cmd, 'r')); return $cmd; }
<?php //php.ini 设置 yaf.use_spl_autoload=on define("APP_PATH", dirname(__DIR__)); /* 指向public的上一级 */ if (!defined('SOOH_INDEX_FILE')) { define('SOOH_INDEX_FILE', 'index.php'); } define('SOOH_ROUTE_VAR', '__'); error_log("-------------------------------------------------------tart:route=" . $_GET['__'] . " cmd=" . $_GET['cmd'] . " pid=" . getmypid()); include dirname(__DIR__) . '/conf/globals.php'; $ini = \Sooh\Base\Ini::getInstance(); $app = new Yaf_Application(APP_PATH . "/conf/application.ini"); $dispatcher = $app->getDispatcher(); if (!empty($reqeustReal)) { $dispatcher->setRequest($reqeustReal); } $view = \SoohYaf\SoohPlugin::initYafBySooh($dispatcher); $dispatcher->returnResponse(TRUE); try { $response = $app->run(); } catch (\ErrorException $e) { $view->assign('code', $e->getCode()); $view->assign('msg', $e->getMessage()); error_log("Error Caught at index.php:" . $e->getMessage() . "\n" . \Sooh\DB\Broker::lastCmd() . "\n" . $e->getTraceAsString() . "\n"); $response = new Yaf_Response_Http(); $response->setBody($view->render('ctrl/action.phtml')); } if ($ini->viewRenderType() === 'json') { header('Content-type: application/json'); }
public static function free($arrConf_or_strModName = null, $subid = null) { if ($arrConf_or_strModName == null) { $ks = array_keys(self::$_instances); } elseif (is_array($arrConf_or_strModName)) { $ks = array(self::idOfConnection($arrConf_or_strModName)); } else { $ini = sooh_ini::getInstance(); $dbid = $ini->get('dbByObj.' . $arrConf_or_strModName); if ($dbid === null) { $dbid = $ini->get('dbByObj.default'); } if (is_array($dbid)) { if ($subid === null) { $ks = array(); foreach ($dbid as $subid) { $ks[] = self::idOfConnection(self::confOfMod($arrConf_or_strModName, $subid)); } } else { $ks = array(self::idOfConnection(self::confOfMod($arrConf_or_strModName, $subid))); } } else { $ks = array(self::idOfConnection(self::confOfMod($arrConf_or_strModName, null))); } } if (sooh_trace::needsWrite(__CLASS__)) { sooh_trace::obj('final free these db(s):', $ks); } foreach ($ks as $id) { if (isset(self::$_instances[$id])) { self::$_instances[$id]->free(); unset(self::$_instances[$id]); } } }
public function runCrond($task = null, $ymdh = null) { //$this->_log->writeCrondLog(null, __FUNCTION__."($task=null, crond)"); clearstatcache(); $ini = \Sooh\Base\Ini::getInstance(); $this->_isManual = false; $dt = \Sooh\Base\Time::getInstance(); if ($dt->hour == 3) { $this->_log->remoreCrondLogExpired(); } if (empty($task)) { // loop and check all new paths in a hour $subdirs0 = array(); for ($i = 0; $i < 6; $i++) { $subdirs = $this->getTaskDirs(); //$this->_log->writeCrondLog(null, __FUNCTION__." scan subdirs,".sizeof($subdirs).' found'); foreach ($subdirs as $subdir) { if (!in_array($subdir, $subdirs0)) { $this->forkTask($subdir . '.*'); $subdirs0[] = $subdir; } } if ($i < 5) { sleep(600); clearstatcache(); } } } elseif (substr($task, -1) == '*') { // loop and check all new class in specify path in a hour $dir = substr($task, 0, -2); $task0 = array(); if ($dir == 'Standalone') { for ($i = 0; $i < 6; $i++) { $tasks = $this->getTasks($dir); //$this->_log->writeCrondLog(null, __FUNCTION__." scan Standalone,".sizeof($tasks).' tasks found'); foreach ($tasks as $task => $fullpath) { if (!in_array($task, $task0)) { $task0[] = $task; $this->forkTask('Standalone.' . $task); } } if ($i < 5) { sleep(600); clearstatcache(); } } } else { for ($i = 0; $i < 60; $i++) { if ($i % 10 == 0) { $tasks = $this->getTasks($dir); //$this->_log->writeCrondLog(null, __FUNCTION__." scan $dir,".sizeof($tasks).' tasks found'); foreach ($tasks as $task => $fullpath) { if (!in_array($task, $task0)) { $task0[] = $task; $this->newTask($dir, $task, $fullpath); } } clearstatcache(); } $ret = $this->loop($dt); if ($i > 50 && $ret == false) { break; } $dt->sleepTo($dt->hour, $dt->minute + 1, $ini->get('crondBatchSleepTo') - 0); } } } else { $r = explode('.', $task); $this->newTask($r[0], $r[1], $this->_baseDir . '/' . $r[0] . '/' . $r[1] . '.php'); for ($i = 0; $i < 60; $i++) { if ($this->loop($dt)) { //$this->_log->writeCrondLog(null, __FUNCTION__." run single,needs sleep to ".$dt->hour.":".($dt->minute+1)); $dt->sleepTo($dt->hour, $dt->minute + 1, $ini->get('crondBatchSleepTo') - 0); } else { //$this->_log->writeCrondLog(null, __FUNCTION__." run single,end no more"); break; } } } //$this->_log->writeCrondLog(null, __FUNCTION__." done"); }
protected static function getDBAndTbNameById(&$tbnameToSet, $splitedId, $isCache = false) { $dbByObj = static::idFor_dbByObj_InConf($isCache); $ini = sooh_ini::getInstance(); $dbId = $ini->get('dbByObj.' . $dbByObj); if (is_array($dbId)) { $i = $splitedId % (sizeof($dbId) - 1); $confIDStr = 'dbConf.' . $dbId[$i + 1]; } elseif (!empty($dbId)) { $confIDStr = 'dbConf.' . $dbId; } else { $tmp = $ini->get('dbByObj.default'); if (empty($tmp)) { $confIDStr = 'dbConf.default'; } else { if (is_array($tmp)) { $i = $splitedId % (sizeof($tmp) - 1); $confIDStr = 'dbConf.' . $tmp[$i + 1]; } else { $confIDStr = 'dbConf.' . $tmp; } } } $conf = $ini->get($confIDStr); if (empty($conf)) { error_log('try find ' . $confIDStr . ' in dbConf failed for ' . $dbByObj); return null; } $db = sooh_dbBroker::getInstance($conf, $dbByObj); if (isset($conf['dbEnums'][$dbByObj])) { $dbname = $conf['dbEnums'][$dbByObj]; } else { $dbname = $conf['dbEnums']['default']; } $tbnameToSet = $dbname . '.' . static::splitedTbName($splitedId, $isCache); return $db; }