Page 1 of 1

file_get_contents returns an empty buffer

Posted: Thu Jun 19, 2008 3:53 pm
by jasongr
Hi,

I am using php 5.2.1
I am using the following snippet to get raw data input to my script:

Code: Select all

 
$buffer = file_get_contents("php://input");
 
This code is invoked about 30,000 every day and in 98% of the times it works fine and I get my input.
However, in a few cases, the buffer that I get is an empty string.
I know that the caller is never sending an empty string, so I am wondering what could cause such problem.

Does anyone have any idea? How would I go about debugging such problem?

regards
Jason

Re: file_get_contents returns an empty buffer

Posted: Thu Jun 19, 2008 3:59 pm
by nowaydown1
Not sure what your issue is. I don't do much with streams. I had a really strange issue once with some custom clustered session handler code. Same sort of scenario, wouldn't act right 1 out of 5,000 times. I wound up just writing another file that tested my problematic code in a for loop over a couple thousand iterations and just ramped up the logging/debugging stuff enough until I could pinpoint the problem.

Just a suggestion for one way you might go about tackling this.

Re: file_get_contents returns an empty buffer

Posted: Thu Jun 19, 2008 4:09 pm
by Zoxive
I had a similar unrelated problem.. In order for me to fix it, I just ended up using a loop and when it returned empty, to have it the process again.

Mine dealt with XML and a 3rd party, so I couldn't find why it would work 90% of the time, so i just ended up adding on another condition so make sure it went threw ok, if it didn't to throw an exception and try again, and after it failed so many times to stop.. and log an error report.