cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: retrieving complete response using curl_exec()

From: Brian Wilkins <brian_at_hcc.net>
Date: Sat, 5 Feb 2005 21:45:25 +0500

I don't get the response from the webserver that way. It works much better
like this:

<?php
   $response = "";
   function register_mac($MAC) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 100);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
        curl_exec($ch);
        $succeeded = curl_errno($ch); // == 0 ? true : false;
        curl_close($ch);
        return;
   }

   function associate_mac($url, $MAC, $PINa, $PINb, $postdata) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 100);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
        curl_exec($ch);
        $succeeded = curl_errno($ch); // == 0 ? true : false;
        curl_close($ch);
        return;
   }

   function read_body($ch, $string)
   {
        global $response;
        $response = $string;
        $length = strlen($string);
        return $length;
   }
?>

> On Wed, 2 Feb 2005, Michael wrote:
>
> > Finally, if I use curl on the command line, I get the whole thing. So it
> > seems like either there's something I'm not doing right in my program, or
> > something isn't set up right.
>
> I'm a curl guy, not a PHP guy. If curl works fine like that, I don't
> know much on how to proceed with the debugging.
>
> > Is there some transfer limit setting somewhere that might be set wrong?
>
> No.
>
> > It also doesn't matter if I set CURL_HTTP_VERSION_1_0 or
> > CURL_HTTP_VERSION_1_1. Since the first one forces the server not to send
> > "Transfer-encoding: chunked", I thought that might help, but it doesn't.
>
> It shouldn't. curl works fine with both.
>
> > What else should I look at? When you say it's a bug on either end, do you
> > have any suggestions as to how I could figure out where the bug is?
>
> Since the command line tool works, I'd guess it is a problem with
> your program or the PHP/curl binding.
>
> --
> Daniel Stenberg -- http://curl.haxx.se -- http://daniel.haxx.se
> Dedicated custom curl help for hire: http://haxx.se/curl.html
Received on 2005-02-06