fopen question.

This is a discussion on fopen question. within the PHP Language forums, part of the PHP Programming Forums category; Is there a limit to how long a URL can be with fopen? I have a very long URL as ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-22-2004
theouimets@hotmail.com
 
Posts: n/a
Default fopen question.

Is there a limit to how long a URL can be with fopen? I have a very
long URL as there are lots of things to be passed some variables and
some XML. It seems to get to a certain point and then produce an error
with no details and just cuts it off.

<?php

$url = 'http://test.com/Test.dll?API=test&XML='.
'&lt;FromLastName&gt;FromLast&lt;/FromLastName&gt;'.
'&lt;FromFirm&gt;FromFirm&lt;/FromFirm&gt;'.
'&lt;FromAddress1&gt;FromAddress1&lt;/FromAddress1&gt;'.
'&lt;FromAddress2&gt;6406IvyLane&lt;/FromAddress2&gt;'.
'&lt;FromCity&gt;Greenbelt&lt;/FromCity&gt;'.
'&lt;FromState&gt;MD&lt;/FromState&gt;'.
'&lt;FromZip5&gt;20770&lt;/FromZip5&gt;'.
'&lt;FromZip4&gt;1234&lt;/FromZip4&gt;'.
'&lt;FromPhone&gt;3019187658&lt;/FromPhone&gt;'.
'&lt;ToAddress1&gt;ToAddress1&lt;/ToAddress1&gt;'.
'&lt;ToAddress2&gt;ToAddress2&lt;/ToAddress2&gt;'.
'&lt;ToAddress3&gt;ToAddress3&lt;/ToAddress3&gt;'.
'&lt;ToAddress4&gt;ToAddress4&lt;/ToAddress4&gt;'.
'&lt;ToAddress5&gt;ToAddress5&lt;/ToAddress5&gt;'.
'&lt;ToAddress6&gt;ToAddress6&lt;/ToAddress6&gt;'.
'&lt;ToCountry&gt;France&lt;/ToCountry&gt;'.
'&lt;ToAPOFPOZip5&gt;&lt;/ToAPOFPOZip5&gt;'.
'&lt;ToPhone&gt;&lt;/ToPhone&gt;'.
'&lt;ToFax&gt;&lt;/ToFax&gt;'.
'&lt;ToEmail&gt;&lt;/ToEmail&gt;'.
'&lt;ShippingContents&gt;&lt;ItemDetail&gt;'.
'&lt;Description&gt;Description1&lt;/Description&gt;'.
'&lt;Quantity&gt;1&lt;/Quantity&gt;'.
'&lt;Value&gt;1&lt;/Value&gt;'.
'&lt;NetPounds&gt;5&lt;/NetPounds&gt;'.
'&lt;NetOunces&gt;0&lt;/NetOunces&gt;'.
'&lt;/ItemDetail&gt;&lt;ItemDetail&gt;'.
'&lt;Description&gt;Descripton2&lt;/Description&gt;'.
'&lt;Quantity&gt;5&lt;/Quantity&gt;'.
'&lt;Value&gt;17&lt;/Value&gt;'.
'&lt;NetPounds&gt;2&lt;/NetPounds&gt;'.
'&lt;NetOunces&gt;2&lt;/NetOunces&gt;'.
'&lt;/ItemDetail&gt;&lt;/ShippingContents&gt;'.
'&lt;GrossPounds&gt;7&lt;/GrossPounds&gt;'.
'&lt;GrossOunces&gt;2&lt;/GrossOunces&gt;'.
'&lt;ImageType&gt;GIF&lt;/ImageType&gt;'.
'&lt;ContentType&gt;Gift&lt;/ContentType&gt;'.
'&lt;HSTariffNumber&gt;&lt;/HSTariffNumber&gt;'.
'&lt;CountryOfOrigin&gt;&lt;/CountryOfOrigin&gt;'.
'&lt;CustomerRefNo&gt;&lt;/CustomerRefNo&gt;'.
'&lt;/CustomsCN22CertifyRequest&gt;';

$aurl=fopen($xml,"r");
while (!feof ($aurl, 4096))
$xml .= fgets($aurl);
fclose ($aurl);
?>

Reply With Quote
  #2 (permalink)  
Old 08-22-2004
steve
 
Posts: n/a
Default Re: fopen question.

"theouimets" wrote:
> Is there a limit to how long a URL can be with fopen? I have a very
> long URL as there are lots of things to be passed some variables

and
> some XML. It seems to get to a certain point and then produce an

error
> with no details and just cuts it off.
>
> snip...
> ?>


http://ca3.php.net/manual/en/functio...et-timeout.php

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-fopen-ftopict142029.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=474952
Reply With Quote
  #3 (permalink)  
Old 08-22-2004
Janwillem Borleffs
 
Posts: n/a
Default Re: fopen question.

theouimets@hotmail.com wrote:
> Is there a limit to how long a URL can be with fopen? I have a very
> long URL as there are lots of things to be passed some variables and
> some XML. It seems to get to a certain point and then produce an error
> with no details and just cuts it off.
>


With long requests it's almost always better to use the POST method instead
of GET.

Consider the following snippet or use one of the many classes available on
the net:

// Construct the request string
$request = "API=test&XML=" . urlencode("&lt;FormLastName...");

// Open connection
$fp = fsockopen("test.com", 80);

// Send the request
fputs($fp, "POST /Test.dll HTTP/1.0\r\n");
fputs($fp, "Host: test.com\r\n");
fputs($fp, "Content-Length: " . strlen($request) . "\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n\r\n");
fputs($fp, "$request\r\n");
fputs($fp, "\r\n");

// Print the response
fpassthru($fp);

// Close the connection
fclose($fp);


JW



Reply With Quote
  #4 (permalink)  
Old 08-22-2004
Janwillem Borleffs
 
Posts: n/a
Default Re: fopen question.

Janwillem Borleffs wrote:
> With long requests it's almost always better to use the POST method
> instead of GET.
>


Be also aware that '&' and '=' are reserved characters in request strings
and are used as parameter and parameter/value separators respectively.

When you send:

$url = 'http://test.com/Test.dll?API=test&XML='.
'&lt;FromLastName&gt;FromLast&lt;/FromLastName&gt;'.

you should urlencode the ampersands in the value of the XML parameter. See
the example I posted before.


JW



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:08 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0