Alifc (#73)
* Update index.php * Update common.php * Update and rename scf.php to tencentscf.php * Create alifc.php * Update common.php * Update alifc.php * Update alifc.php * Update alifc.php * Update normal.php * Update common.php * Update common.php * Update conststr.php * Update normal.php * Update normal.php * Update conststr.php * Update index.php * Update common.php * Rename alifc.php to AliyunFC.php * Rename heroku.php to Heroku.php * Rename normal.php to Normal.php * Rename tencentscf.php to TencentSCF.php * Update common.php * Update conststr.php * Update common.php * Update common.php * Update common.php
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
<?php
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
include 'vendor/autoload.php';
|
||||
include 'conststr.php';
|
||||
include 'common.php';
|
||||
|
||||
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
|
||||
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
||||
include 'platform/scf.php';
|
||||
include 'platform/TencentSCF.php';
|
||||
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
||||
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
|
||||
include 'platform/AliyunFC.php';
|
||||
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
|
||||
include 'platform/heroku.php';
|
||||
include 'platform/Heroku.php';
|
||||
$path = getpath();
|
||||
//echo 'path:'. $path;
|
||||
$_GET = getGET();
|
||||
@@ -21,7 +24,7 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
||||
http_response_code($re['statusCode']);
|
||||
echo $re['body'];
|
||||
} else {
|
||||
include 'platform/normal.php';
|
||||
include 'platform/Normal.php';
|
||||
$path = getpath();
|
||||
//echo 'path:'. $path;
|
||||
$_GET = getGET();
|
||||
@@ -36,6 +39,7 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
||||
echo $re['body'];
|
||||
}
|
||||
|
||||
// Tencent SCF
|
||||
function main_handler($event, $context)
|
||||
{
|
||||
$event = json_decode(json_encode($event), true);
|
||||
@@ -51,3 +55,56 @@ function main_handler($event, $context)
|
||||
|
||||
return main($path);
|
||||
}
|
||||
|
||||
// Aliyun FC
|
||||
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']);
|
||||
}
|
||||
|
||||
// used by Aliyun FC
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user