【发布时间】:2020-04-08 18:52:25
【问题描述】:
我想从一个 lambda 函数到另一个执行 curl 查询。但是邮递员有错误:
{"message": "端点请求超时"}
我试图处理这个错误。我收到此错误消息:
2019-12-16T09:59:27.830Z 4189c32a-1e9c-4898-a59e-6149c49eaab2 任务在 30.03 秒后超时
PHP-FPM 似乎已经在运行,这可能是因为 Lambda 停止了引导过程,但没有给我们留下停止 PHP-FPM 的机会。现在停止 PHP-FPM 以从空白状态重新开始。 致命错误:未捕获的 Bref\Runtime\FastCgi\FastCgiCommunicationFailed:与 PHP-FPM 通信以读取 HTTP 响应时出错。根本原因可能是 Lambda(或 PHP)超时,例如在尝试连接到远程 API 或数据库时,如果发生这种情况,请不断检查!原始异常消息:hollodotme\FastCGI\Exceptions\TimedoutException 在 /var/task/vendor/bref/bref/src/Runtime/PhpFpm.php:126 中读取超时 堆栈跟踪:
0 /opt/bootstrap(30): Bref\Runtime\PhpFpm->proxy(Array)
1 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(92): {closure}(Array, Object(Bref\Context\Context))
2 /opt/bootstrap(34): Bref\Runtime\LambdaRuntime->processNextEvent(Object(Closure))
这是我的代码:
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 500, // timeout on connect
CURLOPT_TIMEOUT => 500, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_USERAGENT => "",
CURLOPT_COOKIESESSION => false,
// CURLOPT_COOKIEJAR => $this->ckfile, // Cookies
// CURLOPT_COOKIEFILE => $this->ckfile, //Cookies...yum
);
//Go go go!
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$output['content'] = curl_exec( $ch );
$output['err'] = curl_errno( $ch );
$output['errmsg'] = curl_error( $ch );
$output['header'] = curl_getinfo( $ch );
dd($output);
当我使用 guzzlehttp:
$client = new \GuzzleHttp\Client();
$request = $client->get($url);
$response = $request->getBody();
我只得到:
任务在 30.03 秒后超时
【问题讨论】:
-
您能否添加有关函数本身的更多信息并查看以下内容 - stackoverflow.com/questions/53898894/…
-
我查阅了一些资料,发现 Lambda 无法连接到 VPC 之外的任何东西。我认为这是 api 网关的问题。我找到了可以在其中创建 VCP 链接的选项卡,这些链接提供对 Amazon Virtual Private Cloud (VPC) 中 HTTP(S) 资源的访问。但现在它不起作用:)
标签: php amazon-web-services curl aws-lambda