简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM