From 95c6657dc12d144ee69042b38eb0bdb634659ff1 Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Thu, 27 Jan 2022 14:50:09 +0800 Subject: [PATCH 1/2] fix aliyun FC platform --- index.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 47131c2..207efaa 100644 --- a/index.php +++ b/index.php @@ -11,13 +11,13 @@ date_default_timezone_set('UTC'); if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php'; else include 'platform/TencentSCF_env.php'; -} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') { +} elseif (isset($_SERVER['FC_RUNTIME_API'])) { include 'platform/AliyunFC.php'; -} elseif ($_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') { +} elseif (isset($_SERVER['_APP_SHARE_DIR']) && $_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') { //if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php'; //else include 'platform/HuaweiFG_env.php'; echo 'FG' . PHP_EOL; -} elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') { +} elseif (isset($_SERVER['BCE_CFC_RUNTIME_NAME']) && $_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') { include 'platform/BaiduCFC.php'; } elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') { include 'platform/Heroku.php'; @@ -106,7 +106,7 @@ function main_handler($event, $context) // Aliyun FC & Huawei FG & Baidu CFC function handler($event, $context) { - if (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') { + if (isset($_SERVER['FC_RUNTIME_API'])) { // Aliyun FC set_error_handler("myErrorHandler"); $tmp = array( @@ -120,6 +120,7 @@ function handler($event, $context) ); $event = $tmp; $context = json_decode(json_encode($context), true); + $context['FC_RUNTIME_API'] = $_SERVER['FC_RUNTIME_API']; printInput($event, $context); unset($_POST); unset($_GET); @@ -130,7 +131,7 @@ function handler($event, $context) $re = main($path); - return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], $re['isBase64Encoded']?base64_decode($re['body']):$re['body']); + return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], ($re['isBase64Encoded']?base64_decode($re['body']):$re['body'])); } elseif ($_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') { // Huawei FG From 79c35daca047b70d50336f69b50a5e8f71727d54 Mon Sep 17 00:00:00 2001 From: Menu Yang Date: Thu, 27 Jan 2022 12:19:41 +0800 Subject: [PATCH 2/2] fix: check aliyun fc with official env var Check aliyun fc with official env var. see example code in: https://help.aliyun.com/document_detail/89032.html use of FC_SERVER_PATH with fixed path php7.2 may not compatible with higher php version --- common.php | 2 +- index.php | 5 ++--- platform/AliyunFC.php | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common.php b/common.php index c651bf3..969054f 100644 --- a/common.php +++ b/common.php @@ -1758,7 +1758,7 @@ output: $canOneKeyUpate = 1; } elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') { $canOneKeyUpate = 1; - } elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') { + } elseif (isset($_SERVER['FC_FUNC_CODE_PATH'])) { $canOneKeyUpate = 1; } elseif (isset($_SERVER['BCE_CFC_RUNTIME_NAME'])&&$_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') { $canOneKeyUpate = 1; diff --git a/index.php b/index.php index 207efaa..807eed4 100644 --- a/index.php +++ b/index.php @@ -11,7 +11,7 @@ date_default_timezone_set('UTC'); if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php'; else include 'platform/TencentSCF_env.php'; -} elseif (isset($_SERVER['FC_RUNTIME_API'])) { +} elseif (isset($_SERVER['FC_FUNC_CODE_PATH'])) { include 'platform/AliyunFC.php'; } elseif (isset($_SERVER['_APP_SHARE_DIR']) && $_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') { //if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php'; @@ -106,7 +106,7 @@ function main_handler($event, $context) // Aliyun FC & Huawei FG & Baidu CFC function handler($event, $context) { - if (isset($_SERVER['FC_RUNTIME_API'])) { + if (isset($_SERVER['FC_FUNC_CODE_PATH'])) { // Aliyun FC set_error_handler("myErrorHandler"); $tmp = array( @@ -120,7 +120,6 @@ function handler($event, $context) ); $event = $tmp; $context = json_decode(json_encode($context), true); - $context['FC_RUNTIME_API'] = $_SERVER['FC_RUNTIME_API']; printInput($event, $context); unset($_POST); unset($_GET); diff --git a/platform/AliyunFC.php b/platform/AliyunFC.php index 191396d..a32b650 100644 --- a/platform/AliyunFC.php +++ b/platform/AliyunFC.php @@ -67,8 +67,8 @@ function GetPathSetting($event, $context) $_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; $_SERVER['referhost'] = explode('/', $event['headers']['Referer'][0])[2]; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['If-Modified-Since'][0]; + $_SERVER['FC_FUNC_CODE_PATH'] = getenv('FC_FUNC_CODE_PATH'); $_SERVER['REQUEST_METHOD'] = $event['method']; - $_SERVER['FC_SERVER_PATH'] = '/var/fc/runtime/php7.2'; return $path; //return spurlencode($path, '/'); }