5
$url = "http://example.com/............."

The $url has about more than 4095 characters . I need to access this URL in php, but if I use file or file_get_contents, it returns an error

How can i open or access this URL in php?

rene
  • 41,474
  • 78
  • 114
  • 152
haitao
  • 51
  • 1
  • 2
  • 7
    Why the bleep would you have an URL that long? – Anze Jarni Jun 10 '11 at 09:24
  • 3
    Please when you get an error, always quote the *exact* message. – Pekka Jun 10 '11 at 09:27
  • I dont have an extremely long URL to try mysel fbut would a Curl request do the trick? – azzy81 Jun 10 '11 at 09:30
  • Hi thanks. This is a long url that can generate some pdf files . When I use curl to open this url, it returns the error:"'HTTP/1.0 414 Error #10068 - HTTP request line exceeds the 4096 character limitation. Content-Type: text/plain Content-Length: 71 Date: Fri, 10 Jun 2011 10:03:07 GMT " – haitao Jun 10 '11 at 10:12
  • The odd thing is that that is a server response code, so the people who host this service using only GET fail to put in the infra-structure to sufficient run it. Or, you know, just bad design by people who don't know what they're doing. *sigh* – AlexanderJohannesen Jun 11 '11 at 05:59

5 Answers5

4

Your problem isn't PHP, it's the madness of your requirement. :) Also ;

What is the maximum length of a URL in different browsers?

Surely you want POST instead of crazy GET. This sounds more like a fundamental problem of the systems design.

Community
  • 1
  • 1
AlexanderJohannesen
  • 2,028
  • 2
  • 13
  • 26
  • Hi thanks, but I can not post this. this is a link that generate a pdf file by a company's url api. they just provide the GET method. – haitao Jun 10 '11 at 10:08
  • 1
    Then I think you need to write them a stern email, and request them to not create such crap. You can word it differently if you must. :) – AlexanderJohannesen Jun 10 '11 at 11:52
1

It depends on server type, which you are trying to access.

For example:

Apache: limits URL length by LimitRequest*, by default it has 8 KBytes for URL string.

Microsoft Internet Information Server: by default it has 16 KBytes. But it can be changed.

Perl HTTP::Daemon: 8,000 chars for URL length and 16 KBytes for HTTP-header. Values can be changed in Daemon.pm.

Ronhul Maggot
  • 81
  • 1
  • 8
  • But there is no client, it is php script oO Or are there restrictions in PHP conf too? – Ronhul Maggot Jun 10 '11 at 09:38
  • hi, thanks. I try the code both at firefox and IE , all return the same error "'HTTP/1.0 414 Error #10068 - HTTP request line exceeds the 4096 character limitation" – haitao Jun 10 '11 at 10:24
1

the error you got was generated by the remote server ... that service can't handle URLs longer than the stated ammount of characters.

if that API relies on GET requests and is meant to be used the way you use it, your problem is a design error in the used API and has nothing to do with PHP. if you can not change the API or the service that provides access to the API, you can not solve this problem

DarkSquirrel42
  • 10,167
  • 3
  • 20
  • 31
0

You should be using POST instead of GET for such amounts of data

  1. Create stream context
  2. Set your context options
  3. Use this context as a 3rd param in file_get_contents()
mkilmanas
  • 3,395
  • 17
  • 27
  • hi thanks. but I can not use POST instead of GET. Thanks for your reference. Can Stream context have an option of the max length of characters? I got the error message "'HTTP/1.0 414 Error #10068 - HTTP request line exceeds the 4096 character limitation. Content-Type: text/plain Content-Length: 71 Date: Fri, 10 Jun 2011 10:03:07 GMT " – haitao Jun 10 '11 at 10:16
  • 1
    If you received this from the API server/service, then it means failure is not on your side, but on theirs. I.e. they do not accept such long URL, and no matter what method you will use, result will be the same. – mkilmanas Jun 10 '11 at 10:55
0

As Raymond Chen once wrote, if you have to ask, you're probably doing something wrong. In your case, you should clearly be using POST instead of GET.

nickf
  • 537,072
  • 198
  • 649
  • 721