curl - PHP CURLOPT_WRITEFUNCTION doesn't appear to be called

Solution:
Lets look at option description from this manual http://www.php.net/manual/en/function.curl-setopt.php:
CURLOPT_WRITEFUNCTION The name of a callback function where the callback function takes two parameters. The first is the cURL resource, and the second is a string with the data to be written. The data must be saved by using this callback function. It must return the exact number of bytes written or the transfer will be aborted with an error.
So, it means what a response can be split into several pieces of data. For appropriate receiving of first 20000 bytes you must add $full_length counter:
$full_length = 0;
function receiveResponse($ch,$string) use (&$full_length) {
$length = strlen($string);
$full_length += $length;
if($full_length >= 20000) { return -1; }
return $length;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to undefined function str_contains()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.