1

*** EDIT - SOLVED ***

In case it may help someone one day, the real cause was due to a malware on my server which was mining crypto through my php-fpm container.

If you want to check :

  • Install htop to your server if it is ot already installed
  • Look for you CPU utilisation if there is a program using all of it
  • Remove it
  • Secure your docker with networks and don't open port 9000

In my case, it was this one "devtmpfsi"

kdevtmpfsi using the entire CPU

*** END OF EDIT ***


I know this error is old like the world but after searching for a solution for about three days on every different websites and topics I couldn't find anything that match my case.

So I hope so someone might help me.

Context :

  • I'm using the function fetch in JS to get my data
  • I'm using docker in dev and prod environnement with nginx (1.10.3) and php-fpm (PHP: 7.4.12)
  • Everything work fine in dev environnement
  • It happen about few minutes / or after multiple refresh of the page, but everything work when I restart docker, and then, happen again

Screenshots of the error

First Screenshot

Second screenshot

Code

JS :

const fetchSkinWithParameters = () => {
        fetch(platformUrl + '/api/skins', {
            method: "POST",
            body: JSON.stringify({
                currentIndex: containerPage1.dataset.currentindex,
                type: containerPage1.dataset.currenttype,
            })
        }).then((res) => {
            return res.json();
        }).then((data) => {
            data = data.data;
            name = data.name;
            totalSkin = data.totalSkin;
            id = data.id;

            skinSelectorPreview.dataset.id = id.toString();
            skinSelectorPreview.setAttribute('src', '/assets/images/skins/' + name);
        });
    }

PHP (symfony 5):

 /**
 * @Route("/api/skins"), name="choose_skin"
 */
public function chooseSkin(Request $request)
{
    $message = json_decode($request->getContent(), true);

    $type = $message['type'];

    $em = $this->getDoctrine();

    $skins = $em->getRepository(Skin::class)->findByType($type);

    $currentIndex = $message['currentIndex'];

    $data = [
        'id' => $skins[$currentIndex]->getId(),
        'name' => $skins[$currentIndex]->getName(),
        'totalSkin' => count($skins),
    ];

    $response = new Response();
    $response->setContent(json_encode([
        'data' => $data,
    ]));
    $response->headers->set('Content-Type', 'application/json');
    $response->setStatusCode(200);

    return $response;
}

Solutions I tried :

  • Modifying my php.ini (output_buffering)
  • Checking if I didn't have stupid spaces before any <?php
  • And many little thing about session (starting a new one an so on)

This is my first in here post since I always found solutions over here, I'm quite annoyed right now :/

I'll provide any informations that you'll need / or I forgot to put in here if you ask

Thanks for your time.

Florian
  • 21
  • 4

1 Answers1

-2

On your JS add headers this way:

fetch(platformUrl + '/api/skins', {
    method: "POST",
    headers: {
         'Accept': 'application/json, text/plain, */*',
         'Content-Type': 'application/json'
    },
    body: JSON.stringify({
          currentIndex: containerPage1.dataset.currentindex,
          type: containerPage1.dataset.currenttype,
    })
})
Moïze
  • 707
  • 8
  • 16