Search code examples
phpjsongoogle-cloud-platformgoogle-cloud-functionshttp-post

Google Cloud Functions PHP 7.4 ignore HTTP requests body longer than around 16000 characters


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


Solution

  • 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.