php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51592 file_get_contents('php://input') - empty string if called more than once
Submitted: 2010-04-18 23:04 UTC Modified: 2010-05-31 16:37 UTC
From: theshop at inbox dot ru Assigned: degeberg (profile)
Status: Closed Package: Streams related
PHP Version: 5.3.2 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: theshop at inbox dot ru
New email:
PHP Version: OS:

 

 [2010-04-18 23:04 UTC] theshop at inbox dot ru
Description:
------------
Second and consecutive calls of file_get_contents('php://input') return empty string if client issued an HTTP command other than 'GET' or 'POST' (see example code). If 'GET' or 'POST' HTTP command was issued file_get_contents('php://input') works correctly.

Not sure if this is cURL related bug, maybe some other PHP package is responsible.

I am using Apache 2.2 and IE8.

Test script:
---------------
#bug_curl.php
$hcurl = curl_init();
curl_setopt($hcurl, CURLOPT_URL, 'http://test/bug.php');
curl_setopt($hcurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($hcurl, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
curl_setopt($hcurl, CURLOPT_POSTFIELDS, 'some request text');
curl_setopt($hcurl, CURLOPT_CUSTOMREQUEST, 'DELETE');
//curl_setopt($hcurl, CURLOPT_HTTPGET, true); - this works ok
//curl_setopt($hcurl, CURLOPT_POST, true); - this works ok
$out = curl_exec($hcurl);
curl_close($hcurl);
echo '<pre>'.htmlspecialchars($out).'</pre>';

# bug.php
var_dump(file_get_contents('php://input'));
var_dump(file_get_contents('php://input')); // returns empty string if HTTP command is not 'GET' or POST'
var_dump(apache_request_headers());


Expected result:
----------------
string(17) "some request text"
string(17) "some request text"
array(4) {
  ["Host"]=>
  string(4) "test"
  ["Accept"]=>
  string(3) "*/*"
  ["Content-Type"]=>
  string(10) "text/plain"
  ["Content-Length"]=>
  string(2) "17"
}



Actual result:
--------------
string(17) "some request text"
string(0) ""
array(4) {
  ["Host"]=>
  string(4) "test"
  ["Accept"]=>
  string(3) "*/*"
  ["Content-Type"]=>
  string(10) "text/plain"
  ["Content-Length"]=>
  string(2) "17"
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-14 13:55 UTC] theshop at inbox dot ru
-Package: cURL related +Package: Streams related -PHP Version: 5.2.13 +PHP Version: 5.3.2
 [2010-05-14 13:55 UTC] theshop at inbox dot ru
Some more test results:

Windows 7 Pro x64, Apache 2.2.15, PHP 5.3.2 - not working.
CentOS (don't know exact version number), Apache 2.2.3, PHP 5.3.2 - works correctly.

So this is probably Windows-only bug.
 [2010-05-14 14:12 UTC] theshop at inbox dot ru
-Operating System: Windows 7 Pro x64 +Operating System: Windows 7 Pro x64, CentOS
 [2010-05-14 14:12 UTC] theshop at inbox dot ru
Nope, I was wrong, does not work under CentOS with methods different from GET or POST. So it is not OS specific after all.
 [2010-05-31 15:12 UTC] mike@php.net
-Status: Open +Status: To be documented -Operating System: Windows 7 Pro x64, CentOS +Operating System: any
 [2010-05-31 15:12 UTC] mike@php.net
Reclassified.

php://input can only be read once.
 [2010-05-31 16:37 UTC] degeberg@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=299993
Log: Fixed PHP bug #51592 (file_get_contents('php://input') - empty string if called more than once)
 [2010-05-31 16:37 UTC] degeberg@php.net
-Status: To be documented +Status: Closed -Assigned To: +Assigned To: degeberg
 [2010-05-31 16:37 UTC] degeberg@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 23:01:27 2024 UTC