Google Cloud功能PHP 7.4忽略HTTP请求比16000个字符更长

发布于 2025-02-03 06:32:47 字数 1057 浏览 2 评论 0原文

问题可能是此问题

这个 将JSON文本发送到我的Google Cloud功能运行php。这是代码的示例:

<?php
use Psr\Http\Message\ServerRequestInterface;
use Google\CloudFunctions\FunctionsFramework;
FunctionsFramework::http('insertbdd', 'insertbdd');

function insertbdd(ServerRequestInterface $request)
{
    $body = $request->getBody()->getContents();
    $size = (int) $_SERVER['CONTENT_LENGTH'];
    fwrite($log, "body : ".$body."\n");
    fwrite($log, "size : ".$size."\n");
    if (!empty($body)) {
        // save to database
    } else {
        die()
    }
}

当我尝试传递约16000个字符的长度的json文件时,一切都很好,但是如果文件的大小超过16000个字符,我什么都没有,身体是空的,并且content_length是0。

我很确定问题在接收方,因为我试图通过php curl,Postman和Google Cloud功能的测试发送JSON。

在另一个问题中, sandeep vokkareni 提到,原因是PHP功能的有效载荷大于16kb。但是,我找不到有关此16KB有效载荷的任何信息。有链接吗?

任何帮助将不胜感激。提前致谢

this question could be a duplicate of this question

I use a HTTP POST request to send a JSON text to my Google Cloud Function running PHP. Here is the example of the codes:

<?php
use Psr\Http\Message\ServerRequestInterface;
use Google\CloudFunctions\FunctionsFramework;
FunctionsFramework::http('insertbdd', 'insertbdd');

function insertbdd(ServerRequestInterface $request)
{
    $body = $request->getBody()->getContents();
    $size = (int) $_SERVER['CONTENT_LENGTH'];
    fwrite($log, "body : ".$body."\n");
    fwrite($log, "size : ".$size."\n");
    if (!empty($body)) {
        // save to database
    } else {
        die()
    }
}

When I try to pass a JSON file of which length is shorter than about 16000 characters, everything is fine, but if the size of the file surpass 16000 characters, I got nothing, the body is empty and the CONTENT_LENGTH is 0.

I am pretty sure the problem is on the receiver side, as I tried to send the JSON by PHP Curl, Postman and the test of Google Cloud Function.

In the other question Sandeep Vokkareni mentioned that the reason is the payload of PHP function being larger than 16kb. However I couldn't find any information about this 16kb payload online. Any link please ?

Any help will be much appreciated. Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蘑菇王子 2025-02-10 06:32:47

我使用具有PHP 7.4的Cloud Function Gen1遇到了同样的问题,我找不到任何使它起作用的方法。

我用php8.1和用云功能Gen2测试了它的作品

I had the same problem using Cloud Function gen1 with php 7.4 and I couldn't find any way to get it work.

I tested with Cloud Function gen2 with php8.1 and it's works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文