Search code examples
phpjsongetmagento2file-get-contents

Magento2/PHP - file_get_contents() returns different output length on 2 different environments


I'm coming here with my first question every since I don't know what to do anymore.

I have an URL(endpoint from an API with 0 security measures) that returns me a 2.5mb json with almost 3000 products. All good here. The thing is:

If I use the following code on LOCALHOST with a XAMPP server... EVERYTHING IS GOOD. My entire returned JSON is valid, I can use json_decode() on it and have my fun with it.

$response= file_get_contents($url);
var_dump($response);

BUT

If I use the same code on my hosting where I have my website in production...all I get is a chunked/sometimes halved JSON that always fails on json_decode();

The problem from what I see..is that I get different sized content.

https://ibb.co/sVDzBMJ

https://ibb.co/h7Z8GT7

In the first image I have a string with the size of 2 551 849 In the escond image I have a string with the size of 817 600

Keep in mind that that's the same code used. The first think I'm thinking right now is that maybe my hosting has a limit on those kind of outputs... ?

Is there such thing? How can I debug this?

I got to the 10th page of Google/Stack and couldn't find anything like that.


Solution

  • It seems that I found the problem.

    My hosting was using LiteSpeed and they have a safe mechanism against DDoS attacks.

    Well it seems that the response from my endpoint was way too big and LiteSpeed thought it was a DDoS attack.

    Disabling such mechanism should fix it.