function loop($callback, $nowait = false, $timeout = 0) { if (!$this->runing) { cy_exit(CYE_SYSTEM_ERROR); } try { $this->callback = $callback; $this->channel->basic_qos(null, 1, null); $this->channel->basic_consume($this->queue, '', false, false, false, false, [$this, 'recv']); do { $this->channel->wait(null, $nowait, $timeout); } while (!$nowait); } catch (Exception $e) { cy_log(CYE_ERROR, $e->getMessage()); } }
/** * 如果脚本中出现异常 ,但未被catch,调用此方法出系统繁忙 * * @ignore * * @param Exception $e 异常堆栈 */ function cy_exception_handler($e) { cy_exit(CYE_UNKNOWN_EXCEPTION); }
global $_g_module, $_g_id, $_g_method, $_g_display; /* get display format. */ if (($p = strrpos($request_uri, '.')) !== false) { $tail = substr($request_uri, $p + 1); if (preg_match('/^[a-zA-Z0-9]+$/', $tail)) { $_g_display = $tail; //'json' $request_uri = substr($request_uri, 0, $p); } } /* get version, module, id, method. */ $requests = array_pad(explode('/', $request_uri, 5), 5, NULL); list(, $_g_module, $_g_id, $_g_method) = $requests; if (empty($_g_module)) { header("Location: " . $_ENV['url_path'] . "/login/0/login.php"); cy_exit(); } /* default format: json */ empty($_g_display) && ($_g_display = 'json'); empty($_g_method) && ($_g_method = 'get'); if (isset($_GET['id'])) { $_g_id = $_GET['id']; } if (isset($_GET['op'])) { $_g_method = $_GET['op']; } $_ENV['module'] = $_g_module; $_ENV['id'] = $_g_id; $_ENV['method'] = $_g_method; $_ENV['display'] = $_g_display; /*-------------------------------------
function get($file = NULL) { /* if(isset($this->data['backtrace'])) { unset($this->data['backtrace']); } */ switch ($this->options['display']) { case 'php': extract($this->data); include $file; break; case 'html': try { $smarty = class_exists('CA_Util_Smarty') ? 'CA_Util_Smarty' : 'CY_Util_Smarty'; $tpl = new $smarty(); /* $tpl->assign("cy_home" , CY_HOME); $tpl->assign("cy_url_base" , $_ENV['url_base']); $tpl->assign("cy_url_path" , $_ENV['url_path']); $tpl->assign("cy_id" , $_ENV['id'] ); // cy_user_id 放这里不合适,但先就这样了吧 $tpl->assign("cy_user_id" , $_ENV['session']->user_id()); */ $tpl->assign($this->data); return $tpl->fetch($file); } catch (Exception $e) { if ($_ENV['debug']) { if (empty($this->data['exitting'])) { cy_exit(CYE_TEMPLATE_ERROR, "Smarty template exception:" . $e->getMessage() . " On " . $file); } else { echo "Smarty template exception:" . $e->getMessage() . " On " . $file; exit; } } } case 'jsonh': // TODO: use smart here. break; case 'json': if (PHP_SAPI !== 'cli') { header('Content-Type: application/json'); } return json_encode($this->data); case 'jsonp': //header('Content-Type: application/jsonp'); $method = isset($_GET['method']) ? trim($_GET['method']) : 'callback'; if (!preg_match('/^[0-9a-zA-Z_]+$/', $method)) { $method = 'callback'; } return $method . "(" . json_encode($this->data) . ");"; case 'raw': if (empty($this->data['data'])) { return ''; } return $this->data['data']; case 'xml': default: break; } return ''; }