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


using curl from another class?

From: Kenneth Andresen <>
Date: Sun, 23 Jul 2006 19:44:23 -0500

Hello all,

I am trying to use my curl within my own class in php5, and believe I
should be quite close; the problem seems to be that the 'read_header'
function is not found within the class. I have tried replacing it with
this->read_header, this::read_header, self::read_header, and so on
without luck. Can this be done, or am I on the wrong track here?

    public $result;
    public $result_header;
    public $result_error;

    public funtion test_curl($ch) {
        curl_setopt($ch, CURLOPT_URL, '');
        // Set callback function for headers
        curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $this->result = curl_exec($ch);
        $this->result_header = ob_get_contents();
        if ($error = curl_error($ch)) {
            echo "Error: $error<br />\n";
# $this->result_error = $error;

     static function read_header($ch, $string)
        $length = strlen($string);
        echo "$string";
        return $length;

$ch = curl_init();
$test = new test_curl($ch); # this result in Error: failed writing

I did also try to extend curl_init without luck:

class my_curl extends curl_init {
    private $header;
    private $result_header;

Received on 2006-07-24