/** * 开始处理产品数据 */ public function runAction() { //$pid = 16607872; //$pid = 16665795; //$this->moveProduct($pid); //exit; $di = \Phalcon\DI::getDefault(); $di->setShared('beanstalkd', function () { $queue = new SocketBeanstalk(array('host' => '192.168.8.189', 'port' => 11300)); return $queue; }); while (1) { \Xz\Lib\Core\RunTime::start(); $di->get("beanstalkd")->watch("forbuyers_product_move"); $job = $di->get("beanstalkd")->reserve(1); if (empty($job)) { sleep(1); continue; } $result = ""; $result = !empty($job['body']) ? $job['body'] : array(); if (empty($result)) { sleep(1); continue; } $di->get("beanstalkd")->delete($job['id']); $pidArr = json_decode($result, true); foreach ($pidArr as $pid) { $this->moveProduct($pid); } } }
/** * @desc 致命错误的捕获 **/ public function throwParseError() { $error = error_get_last(); if ($error && in_array($error['type'], array(1, 4, 16, 64, 256, 4096, E_ALL))) { $error = array('code' => $error['type'], 'msg' => $error['message'], 'trace' => $error['file'] . ' In Line:' . $error['line'], 'data' => '', 'runTime' => RunTime::getTime()); $this->pushError($error); $this->renderError($error); } }
public function __construct($appPath, $mode = 'Web') { RunTime::start(); $cfgvar = get_cfg_var('phaplus.env'); $env = !empty($cfgvar) ? $cfgvar : 'dev'; define('APP_MODE', $this->modeMap[$mode]); define('APP_ROOT', rtrim($appPath, '/') . '/'); define('APP_ENV', $env); $this->init(); }
/** * 格式化数据结构 * @author 孟伟 * @datetime 2015年07月28日15:35:47 * * @param string $data * @param int $code * @param string $msg * @return array */ public function outputData($data = '', $code = 200, $msg = '') { if (is_object($data)) { $data = $data->toArray(); } $resultData = array('code' => $code, 'msg' => $msg, 'runTime' => RunTime::getTime(1)); if (isset($data['count'])) { $resultData['count'] = $data['count']; unset($data['count']); } $resultData['data'] = $data; return $resultData; }
public function afterDispatch(Event $event, \Phalcon\Mvc\Dispatcher $dispatcher) { $app = self::getProject(); if (strpos($app, 'gc.operator') === false && strpos($app, 'gc.front') === false) { return; } $di = DI::getDefault(); $router = $di['router']; $module = $router->getModuleName(); $controller = $router->getControllerName(); $action = $router->getActionName(); $uri = $module . '\\' . $controller . '\\' . $action; $code = intval($di['response']->getStatusCode()); $monitor = $di['config']->swoole_monitor; $client = new \swoole_client(intval($monitor->protocol)); $connect = $client->connect($monitor->host, $monitor->port, $monitor->timeout); $data = ['project' => self::getProject(), 'service' => trim($uri, '\\'), 'action' => '', 'timeStamp' => time(), 'runTime' => RunTime::getTime(), 'code' => empty($code) ? 200 : $code, 'errorSummary' => '', 'serviceIp' => self::getLocalip(), 'baseIp' => '', 'errorDetail' => array()]; $client->send(json_encode($data)); $client->close(); }
public function callService($data) { echo "service is doing:.\n"; var_dump($data); echo ".\n"; \Xz\Lib\Core\RunTime::start(); // 判断数据是否正确 if (empty($data['data']['service']) || empty($data['data']['method']) || !isset($data['data']['args'])) { // 发送数据给客户端,请求包错误 return array('fd' => $data['fd'], 'data' => array('code' => 600, 'msg' => 'bad request', 'data' => 0)); } $di = new \Phalcon\DI(); require APP_ROOT . 'apps/config/loaderyar.php'; $backend = new \Xz\Lib\Core\BackendServer(); $ret = array(); $ret['data'] = $backend->callService($data['data']); $ret['fd'] = $data['fd']; \Phalcon\DI::reset(); echo "service is complete:.\n"; var_dump($ret); echo ".\n"; return $ret; }
public function errorCallback($type, $error, $callinfo) { if (is_array($error)) { self::$result[$callinfo['sequence']]['code'] = $error['code'] ? $error['code'] : 600; self::$result[$callinfo['sequence']]['msg'] = $error['message']; self::$result[$callinfo['sequence']]['trace'] = $error['file'] . ' In line:' . $error['line']; } else { self::$result[$callinfo['sequence']]['code'] = '600'; self::$result[$callinfo['sequence']]['msg'] = $error; self::$result[$callinfo['sequence']]['trace'] = ''; } self::$result[$callinfo['sequence']]['data'] = ''; self::$result[$callinfo['sequence']]['runTime'] = RunTime::getTime(); $this->pushError($this->rawData[$callinfo['sequence']], self::$result[$callinfo['sequence']]); }