The Lurker
Header and body curl callback functions in PHP
OK, I just found the bug that was screwing up my LiveJournal "last modified" hack. It's still only a rough guess because LJ doesn't make the date available to anonymous users, but it wasn't working at all before. Since this seems to be undocumented on the PHP site, I'll put what I learned here in the hope that a search engine will pick it up and help out the next poor fool who wants to use it:
The curl options CURLOPT_HEADERFUNCTION and CURLOPT_WRITEFUNCTION can be set to either a function, or an (object, method name) array (just like the first argument to call_user_func). Both are callbacks which are called as data is received from the HTTP server, but they have different arguments. The header function's first argument is a single line from the response header, and its second is a boolean (which was always true in the callbacks my code was getting, so I don't know what it's supposed to mean). For the write function, however, the first is the curl resource (ie, the thing that was created by curl_init()), and the second is the body data.
Oddly enough, I discovered the write callback's second argument because
when I searched Google for CURLOPT_WRITEFUNCTION I found a web page
where the PHP code start and close tags <? ?>
had
accidentally been escaped, so the code appeared in the web page
instead of being executed on the server.
Related topics: Web
All timestamps are Melbourne time.