Wednesday, 6 May 2009

View the raw HTTP request body in PHP

I'm currently working on a bug where some Japanese characters are not appearing correctly on the FreeFixer web site. In the process of tracking down the problem I needed to view the raw HTTP request body that FreeFixer sends when posting information about a file or some registry data. In PHP, this can be done by calling the http_get_request_body() function. Unfortunately, this function requires a PECL extension which was unavailable in my current setup. However, this solved the problem:

$request_body = @file_get_contents('php://input');


  1. Gorgeous! Exactly what I needed. Thank you very much indeed.

  2. I was also looking for this! It made the trick! Thanks a lot.

  3. Wrong.

    Use this instead:

    $request_body = @file_get_contents(STDIN);

    php://input can only be read once and does not support seek operations. Also php://input can not read the body if a form is posted with enctype="multipart/form-data".

    You can read more here:

    The STDIN constant should be used in place of 'php://stdin'.

    1. I've found that for purposes of reading xml submissions to a controller function, php://input works just fine since you only have to read it once (like push notifications)