Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP CURLOPT_PROGRESSFUNCTION add extra custom parameter to function

Tags:

php

curl

I was wondering if it is possible to add an custom parameter to the function called when using

curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, array($this, 'progressFunction'));

so the function signature would look like

private function progressFunction($clientp, $dltotal, $dlnow, $ultotal, $ulnow, $myCustomParameter) { }

instead of

private function progressFunction($clientp, $dltotal, $dlnow, $ultotal, $ulnow) { }

Thanks.

like image 507
xorinzor Avatar asked Jun 28 '26 09:06

xorinzor


1 Answers

Ok this is strictly a suggestion and i will put it as an answer because i think it may work;

Php supports anonymous functions so you can pass it like so:

curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function ($clientp, $dltotal, $dlnow, $ultotal, $ulnow) {

});

Now the trick is to pass your parameters using the use so:

curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function (...) use ($myCustomParameter) {
    // Your code
    });
like image 129
Ibu Avatar answered Jun 30 '26 00:06

Ibu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!