note 98491 added to function.curl-setopt
| From: | JScottjscott401 at gmail dot com | Date: | Fri, 18 Jun 2010 14:29:21 +0000 |
| Subject: | note 98491 added to function.curl-setopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170238@lists.php.net to get a copy of this message | ||
Some additional notes for curlopt_writefunction. I struggled with this at first because it really
isn't documented very well.
When you write a callback function and use it with curlopt_writefunction it will be called MULTIPLE
times. Your function MUST return the ammount of data written to it each time. It is very picky about
this. Here is a snippet from my code that may help you
<?php
curl_setopt($this->curl_handle, CURLOPT_WRITEFUNCTION, array($this,
"receiveResponse"));
// later on in the class I wrote my receive Response method
private function receiveResponse($curlHandle,$xmldata)
{
$this->responseString = $xmldata;
$this->responseXML .= $this->responseString;
$this->length = strlen($xmldata);
$this->size += $this->length;
return $this->length;
}
?>
Now I did this for a class. If you aren't doing OOP then you will obviously need to modify this
for your own use.
CURL calls your script MULTIPLE times because the data will not always be sent all at once. Were
talking internet here so its broken up into packets. You need to take your data and concatenate it
all together until it is all written. I was about to pull my damn hair out because I would get
broken chunks of XML back from the server and at random lengths. I finally figured out what was
going on. Hope this helps
----
Server IP: 208.69.120.55
Probable Submitter: 192.146.112.8
----
Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php
Edit -- https://master.php.net/note/edit/98491
Del: integrated -- https://master.php.net/note/delete/98491/integrated
Del: useless -- https://master.php.net/note/delete/98491/useless
Del: bad code -- https://master.php.net/note/delete/98491/bad+code
Del: spam -- https://master.php.net/note/delete/98491/spam
Del: non-english -- https://master.php.net/note/delete/98491/non-english
Del: in docs -- https://master.php.net/note/delete/98491/in+docs
Del: other reasons-- https://master.php.net/note/delete/98491
Reject -- https://master.php.net/note/reject/98491
Search -- https://master.php.net/manage/user-notes.php