linux服務(wù)器上啟動(dòng)workerman
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\worker;
use think\App;
use think\Error;
use think\exception\HttpException;
use Workerman\Protocols\Http as WorkerHttp;
/**
* Worker應(yīng)用對(duì)象
*/
class Application extends App
{
/**
* 處理Worker請(qǐng)求
* @access public
* @param \Workerman\Connection\TcpConnection $connection
* @param void
*/
public function worker($connection)
{
try {
ob_start();
// 重置應(yīng)用的開始時(shí)間和內(nèi)存占用
$this->beginTime = microtime(true);
$this->beginMem = memory_get_usage();
// 銷毀當(dāng)前請(qǐng)求對(duì)象實(shí)例
$this->delete('think\Request');
$pathinfo = ltrim(strpos($_SERVER['REQUEST_URI'], '?') ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI'], '/');
// $this->request
// ->setPathinfo($pathinfo);
$this->request
->setPathinfo($pathinfo)
->withInput($GLOBALS['HTTP_RAW_REQUEST_DATA']);
if ($this->config->get('session.auto_start')) {
WorkerHttp::sessionStart();
}
// 更新請(qǐng)求對(duì)象實(shí)例
$this->route->setRequest($this->request);
$response = $this->run();
$response->send();
$content = ob_get_clean();
// Trace調(diào)試注入
if ($this->env->get('app_trace', $this->config->get('app_trace'))) {
$this->debug->inject($response, $content);
}
$this->httpResponseCode($response->getCode());
foreach ($response->getHeader() as $name => $val) {
// 發(fā)送頭部信息
WorkerHttp::header($name . (!is_null($val) ? ':' . $val : ''));
}
$connection->send($content);
} catch (HttpException $e) {
服務(wù)器啟動(dòng)worker后服務(wù)端返回錯(cuò)誤信息。
ErrorException in Application.php Undefined index: HTTP_RAW_REQUEST_DATA