tp5 Loader.php,tp5集成swoole 报错 argv in /var/www/tp5/thinkphp/library/think/Loader.php:61

  • Post author:
  • Post category:php


PHP Fatal error:  Uncaught think\exception\ErrorException: Undefined index: argv in /var/www/tp5/thinkphp/library/think/Loader.php:61

这是错误信息,

$http = new swoole_http_server(‘127.0.0.1’,9501);

$http->set([

‘enable_static_handler’=>true,

‘document_root’=>__DIR__.’/../public’,

‘worker_num’=>4,

]);

$http->on(‘WorkerStart’,’onWorkerStart’);

$http->on(‘request’,’onRequest’);

$http->on(‘close’,’onClose’);

function onWorkerStart(swoole_server $server,$worker_id){

echo ‘worker start:’.$worker_id.PHP_EOL;

require __DIR__.’/../thinkphp/base.php’;

}

function onRequest($request,$response){

$_SERVER = [];

if(isset($request->server)){

foreach($request->server as $key=>$value){

$_SERVER[strtoupper($key)]= $value;

}

}

if(isset($request->header)){

foreach($request->header as $key=>$value){

$_SERVER[strtoupper($key)] = $value;

}

}

$_GET = [];

if(isset($request->get)){

foreach($request->get as $key=>$value){

$_GET[$key]= $value;

}

}

$_POST = [];

if(isset($request->post)){

foreach($request->post as $key=>$value){

$_POST[$key]= $value;

}

}

$_COOKIE = [];

if(isset($request->cookie)){

foreach ($request->cookie as $key => $value) {

$_COOKIE[$key] = $value;

}

}

ob_start();

\think\Container::get(‘app’)->run()->send();

$content = ob_get_contents();

ob_end_clean();

//$msg = ‘this is the request’;

$response->end($content);

};

function onClose($server,$fd){

echo ‘client ‘.$fd.’ get closed’.PHP_EOL;

}

$http->start();

这是代码,tp版本是5.1.19