From http://curl.haxx.se/libcurl/php/examples/callbacks.html