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

curl-and-php

passing data back from curl callbacks in php

From: Thorben Thuermer <t.thuermer_at_mediaclipping.de>
Date: Wed, 29 Oct 2008 16:16:01 +0100

Hello,

i've been using libcurl in C programs before, but now i'm trying to use the php
binding to do similar stuff, and i'm running into the following issue:

- libcurl uses callbacks to pass received headers and data back to the application
- the callbacks can be set with the php api

- with the C api, a userdata pointer (CURLOPT_READDATA) is passed to the callback,
  also you can store userdata in the curl handle (CURLOPT_PRIVATE) which is
  available from inside the callback by using getopt on the handle...
- in the php api those two are missing?!?

so, with the php api, it seems that the only way to pass results of processing the
data or headers back to the application from within the callbacks is using global
variables, which is really ugly...

am i missing something maybe?

(if you can't see the relevance:
i'm writing a function that passes through data from a remote server, but in the
case that the headers indicate an error, i need to pass control back to the caller
(by returning an error message).
that error would be detected in the headerfunction, but there's no way to pass a
message from there back to the point where curl_exec was invoked, other than by
setting a global variable.
if it was possible to pass a variable reference using READDATA or PRIVATE, that
could be used.
a similar problem would be trying to store cookies from the headers, for example)

Greetings,
 Thorben Thuermer
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-10-29