From 3fb1193aa0267efc122d8998c7e74487db9e97f6 Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Tue, 2 Jun 2020 18:31:53 +0800 Subject: [PATCH] Update index.php --- index.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 8455cca..db894db 100644 --- a/index.php +++ b/index.php @@ -1,12 +1,12 @@ '. json_encode($_SERVER, JSON_PRETTY_PRINT).''; if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { - include 'platform/scf.php'; + include 'platform/tencentscf.php'; } elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') { include 'platform/heroku.php'; $path = getpath(); @@ -20,6 +20,9 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { } http_response_code($re['statusCode']); echo $re['body']; +} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') { + //echo '
'. json_encode($_SERVER, JSON_PRETTY_PRINT).'
'; + include 'platform/alifc.php'; } else { include 'platform/normal.php'; $path = getpath(); @@ -51,3 +54,54 @@ function main_handler($event, $context) return main($path); } + +function handler($request, $context) +{ + set_error_handler("myErrorHandler"); + $event = array( + 'method' => $request->getMethod(), + 'clientIP' => $request->getAttribute("clientIP"), + 'requestURI' => $request->getAttribute("requestURI"), + 'path' => spurlencode($request->getAttribute("path"), '/'), + 'queryString' => $request->getQueryParams(), + 'headers' => $request->getHeaders(), + 'body' => $request->getBody()->getContents(), + ); + $context = json_decode(json_encode($context), true); + printInput($event, $context); + unset($_POST); + unset($_GET); + unset($_COOKIE); + unset($_SERVER); + GetGlobalVariable($event); + $path = GetPathSetting($event, $context); + + $re = main($path); + + return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], $re['body']); +} + +function myErrorHandler($errno, $errstr, $errfile, $errline) { + if (!(error_reporting() & $errno)) { + return false; + } + switch ($errno) { + case E_USER_ERROR: + $errInfo = array( + "errorMessage" => $errstr, + "errorType" => \ServerlessFC\friendly_error_type($errno), + "stackTrace" => array( + "file" => $errfile, + "line" => $errline, + ), + ); + throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); + break; + + default: // E_USER_WARNING | E_USER_NOTICE + break; + } + + /* Don't execute PHP internal error handler */ + return true; +}