Search code examples
phpcurlasynchronouscallbackcurl-multi

Is it possible to use curl_multi_getcontent and CURLOPT_WRITEFUNCTION together?


I have an asynchronous curl crawler which works well without CURLOPT_WRITEFUNCTION enabled.

I am trying to limit the amount of data downloaded with CURLOPT_WRITEFUCNTION by stopping any downloads that go over 1mb in size.

The problem I am having is that curl_multi_getcontent($done['handle']) doesn't return any data when I use CURLOPT_WRITEFUCNTION.

I know I can play with the data inside of CURLOPT_WRITEFUCNTION's function, but it would make things much easier if curl_multi_getcontent($done['handle']) continued to do it's job in conjunction with CURLOPT_WRITEFUCNTION.

Is it possible to use curl_multi_getcontent and CURLOPT_WRITEFUNCTION together?


Solution

  • The answer to my own question is this:

    CURLOPT_RETURNTRANSFER is basically a built in WRITEFUNCTION.

    When you specify another WRITEFUNCTION, you override CURLOPT_RETURNTRANSFER and thus have to RETURNTRANSFER yourself if that's what you're trying to do.

    I wish the php curl package would have thrown an error along the lines of "warning: CURLOPT_WRITEFUNCTION overrides CURLOPT_RETURNTRANSFER" but I'm sure they have their reasons for not doing so.