I have a function inside a class that runs a cURL. In the cURL I'm using:
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progress');
The progress function is inside the class, and using its properties and its methods. ($this->property
, $this->method()
)
When I run the script, I get this error message:
Warning: curl_exec(): Cannot call the CURLOPT_PROGRESSFUNCTION in ...
So the question is: Can I do that? And if so, how?
Edit: I have tried to change the code to this:
$ref =& $this;
curl_setopt($ch,
CURLOPT_PROGRESSFUNCTION,
function($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($ref)
{
$ref->progress($resource, $download_size, $downloaded, $upload_size, $uploaded);
}
);
But I'm still getting the same error.
Update: The solution of @Ohgodwhy is working, just make sure that your callback function doesn't have any errors.
Instead, pass in an array with a reference to the object as the first parameter and the function name as the second.
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, array($this, 'method'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With