Is there a maximum length for the URI in the file_get_contents()
function in PHP?
3 Answers
I suppose there is a maximum length, but you'll be hard pressed to find it. If you do hit the maximum, you're doing something wrong. :)
I haven't been able to find a number for PHP specifically, but MS IIS, Apache and the Perl HTTP::Daemon seem to have limits between 4,000 and 16,384 bytes, PHP will probably be somewhere around there as well.
What you need to consider is not really how much your side can handle, but also how much the other server you're querying can handle (which is presumably what you're doing). As such, any URL longer than ~1000 characters is usually already way too long and never really encountered in the real world.

- 510,633
- 85
- 743
- 889
-
I think that's the issue, my URI is really long because it contains a lot of GET data – Brian Mar 31 '10 at 03:56
-
@Brian If data is too long for GET, you're usually supposed to use POST. Can you clarify where you're using this? – deceze Mar 31 '10 at 04:01
-
Because the system was built in this way, there's nothing I can do to change the GET to POST, I'm just trying to access the output as a string – Brian Mar 31 '10 at 04:22
-
@Brian If that system requires such long URLs and there's no other way to pass it all required parameters, I'd call it broken. – deceze Mar 31 '10 at 04:24
-
1I disagree with the last paragraph of this answer. I'm dealing with the Google+ API for searching public activities. `file_get_contents()` is perfect for fetching the first page, but for the next page of results, there's a token that goes in the URL, extending the URL length to 1239 characters, causing the function to fail. Twitter and Facebook include similar tokens for their search result pagination and I would say this is very much a "real world" scenario. – Andy E Jan 18 '12 at 16:55
-
Bing maps API. Ridiculously long queries. I guess it is a microsoft product though, so maybe we're wrong to use it. – ReactiveRaven Jun 08 '12 at 14:43
-
Same with Google Maps Imagery API. I need a preview of a map with 300 dots ;) http://MumImHere.info – Nico Jan 18 '15 at 21:22
As others have stated, it is most likely limited by the HTTP protocol.
You can view this answer for more info on that : What is the maximum length of an url?
In HTTP there's no length-limit for URI,and there's no note of file_get_contents()
about this in the manual .So I think you needn't to consider about this problem.
BTW,the length of URI is limited by some browser and webserver.For example,in IE,the length should be less than 2083 and in FF it's 65,536.I tried to test this I found that only not more than 8182 is OK when I visited my apache on ubuntu because of limit of my apache.

- 7,986
- 7
- 43
- 64