[PHP] Read the raw HTTP request body

Created on November 29, 2026

You can read the raw HTTP request body from the php://input stream. Save this example as get_request_body.php.

<?php

$requestBody = file_get_contents('php://input');
var_dump($requestBody);

Start the PHP development server from the directory containing the file.

php -S localhost:7766

From another terminal, send a POST request with a JSON body.

curl -H 'Content-Type: application/json' \
    -d '{"name": "Tom"}' http://localhost:7766/get_request_body.php

The response shows the raw 15-byte string.

string(15) "{"name": "Tom"}"
PHP