Skip to content

Commit

Permalink
心跳检测 task 重置
Browse files Browse the repository at this point in the history
  • Loading branch information
东流 committed Jan 29, 2018
1 parent 9f24cf6 commit de99cfd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion App.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function reloadSwoole($service,$env)
$app = new \ultraman\Http\HttpYafServer();
}
}
die;
return;
}


Expand Down
3 changes: 1 addition & 2 deletions Exception/BaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

class BaseException extends \Exception
{
public function __construct($message=null,$code = null) {
public function __construct($message=null,$code) {
if(is_null($message)) {
$message = $this->message;
}
if(is_null($code)) {
$code = $this->code;
}

parent::__construct($message, $code);
}
}
13 changes: 9 additions & 4 deletions Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace ultraman\Exception;

class Exception extends BaseException
class Exception extends \Exception
{
protected $code = 500;
protected $message = 'API Call Error';
}
public function __toString()
{
$data['msg'] = $this->message;
$data['code'] = $this->code;
header('Content-Type:application/json; charset=utf-8');
return json_encode($data);
}
}
22 changes: 13 additions & 9 deletions Http/HttpYafServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class HttpYafServer
{
protected $application;
protected $http;
public function __construct()
{
new \ultraman\App();
Expand All @@ -26,9 +27,9 @@ private function run()
$config = @parse_ini_file(APPLICATION_PATH."/conf/main.ini",true);
$http_service = $config['http-service'];
$app = new \ultraman\Http\SwooleHttpServer($http_service);
$http = $app->connent();
\Yaf_Registry::set('swoole_http', $http);
$http->on('WorkerStart' , array( $this , 'onWorkerStart'));
$http = $app->connent();
$this->http = $http;
$http->on('WorkerStart' , array( $this , 'onWorkerStart'));
$http->on('request', array($this, 'onRequest'));
$http->on('Start', array($this, 'onStart'));
$http->on('task', array($this, 'onTask'));
Expand All @@ -43,21 +44,24 @@ public function onRequest($request,$response)
$response->end();
return;
}

\Yaf_Registry::set('swoole_http', $this->http);
$this->initRequestParam($request);
ob_start();
try {

$yaf_request = new \Yaf_Request_Http($request->server['request_uri']);
$this->application->getDispatcher()->dispatch($yaf_request);

} catch ( \Exception $e ) {
} catch ( \Exception $e ) {
$data = \Yaf_Registry::get('Exception');
$params = [
'code'=>$e->getCode(),
'msg'=>$e->getMessage(),
'errcode'=>$e->getCode(),
'errmsg'=>$e->getMessage(),
];
];
if($data!=""){
$params['data'] = $data;
\Yaf_Registry::set('Exception','');
}
echo json_encode($params,JSON_UNESCAPED_UNICODE);
}
$result = ob_get_contents();
Expand All @@ -81,7 +85,7 @@ public function onWorkerStart($serv, $worker_id)
'msg'=>$e->getMessage(),
'errcode'=>$e->getCode(),
'errmsg'=>$e->getMessage()
];
];
echo json_encode($params,JSON_UNESCAPED_UNICODE);
}

Expand Down
2 changes: 1 addition & 1 deletion Yaf/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class ErrorController extends \Yaf_Controller_Abstract
{
public function errorAction($exception)
{

$params = [
'code'=>$exception->getCode(),
'msg'=>$exception->getMessage()
];

header('Content-Type: application/json; charset=utf-8');
echo Response::_end($params,(string)$params['code']);
}
Expand Down

0 comments on commit de99cfd

Please sign in to comment.