file_get_contents returns an empty buffer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

file_get_contents returns an empty buffer

Post 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
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: file_get_contents returns an empty buffer

Post 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.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: file_get_contents returns an empty buffer

Post 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.
Post Reply