Results 1 to 8 of 8

Thread: fgets

  1. #1
    Join Date
    Jan 2004
    Posts
    6

    Unanswered: fgets

    Hi, I seem to be having some trouble with my fgets. I have done a http post to a database using fsockopen and fputs which works fine the database will return xml of the result which is also fine except for the fact that if the response xml is too big (ie. i think larger than 1877 characters) I start to get crlf and the number 2000 put in?? which cause a parse error as i try to put this data through a xml parser??

    Any Ideas??

    I have tried to crank up to amount of bytes that the fgets read in the while loop i.e.
    while(!feof ($fp)) $resp = fgets($fp, 10000);
    but that seems to have no effect in the placement of these inserted characters

  2. #2
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    I don't know what the prolem here is really but the question is if you really need line buffered reading as you seem to want the whole stream anyway. Just using fread could save you a lot of hassle there.

    Edit: reading your other post you probably have a good reason to use line buffered reads in this case
    Last edited by Apel; 01-30-04 at 10:41.

  3. #3
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: fgets

    Originally posted by stuart_d
    Hi, I seem to be having some trouble with my fgets. I have done a http post to a database using fsockopen and fputs which works fine the database will return xml of the result which is also fine except for the fact that if the response xml is too big (ie. i think larger than 1877 characters) I start to get crlf and the number 2000 put in?? which cause a parse error as i try to put this data through a xml parser??

    Any Ideas??

    I have tried to crank up to amount of bytes that the fgets read in the while loop i.e.
    while(!feof ($fp)) $resp = fgets($fp, 10000);
    but that seems to have no effect in the placement of these inserted characters
    fgets has a 4096 byte limit! So the number what you specified is irelevant for this function so when you put n>4096 then fgets read only 4096 bytes.

  4. #4
    Join Date
    Jan 2004
    Posts
    6
    Even when I change the format to a freads and specify the the file limit at 1mb it still every 1877 characters puts the number 2000 or simular

  5. #5
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    Sounds unlikely but just to be sure. Have you tested if your stdio lib is working properly? I think php just imports these functions.

  6. #6
    Join Date
    Jan 2004
    Posts
    6

    Red face

    not exactly sure how to check that but I have just tried it using fpaasthru and output buffers and it still does the say thing this is starting to get annoying

  7. #7
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    Looking at the php source a bit it seems they do quite a lot more than just pass a call to the OS. They don't seem to use the ANSI streams at all. Maybe we need to look elsewhere for the problem. Can you test the database and php seperately? Maybe just try to read a normal file on your disk for php and POST the data to your database via a simple test HTML form.

  8. #8
    Join Date
    Jan 2004
    Posts
    6

    Cool

    SORTED IT YAAAAAAAA!!!

    Turns out it was my fault (sorry for ever doubting you php!!) anyway the problem was to do with how I was defining the
    HTTP headers POST the request to the database server in the first place, I was defining my HTTP protocal as
    HTTP/1.1 which tells the server to Type-encode the response to CHUNKED which is why the fread, fgets, fpassthru all didn't work as it was arriving that way. I have now changed it back to HTTP/1.0 and it work beautifully. Thanks to everyone that put their two cents in.


    Cheers

    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •