I'm using the option of curls so take care to specify a callback when data CRL makes the request.
$ serverid = 5; $ Ch = curl_init (); Curl_setopt ($ c, CURLOPT_URL, 'http://www.whatever.com'); Curl_setopt ($ ch, CURLOPT_WRITEFUNCTION, function ($ ch, $ string) {Read read callback ($ ch, $ string, $ serverid);}); Curl_exec ($ ch); Read the functionbackback ($ ch, $ string, $ serverid) {resonant "server #", $ serverid, "|", $ string; Return Strangel ($ string); } I I would like to use an unknown function to call your own function that actuall work ( readCallback () ) so that Can be able to associate with server ID ( $ serverid ). How can I use Closure / can do so when my callback mismatch function may be affected, was known unknown function that is basically defined by $ serverid = 5 and ReadCallback () is appropriate? I will eventually use it with L and a common callback, this is the reason why I need to call my callback with an unknown function id.
If you want to access the $ server inside your anonymous function, Need to tell that you want to use that variable This way:
/ * * I pass the value 'variable took $ $ $ server ID var instead of $ serverIdHolder Because' use, so your anonymous function Will not change inside. But if you pass any reference * to an object, you can always see the current required value. * / $ ServerIdHolder = new stud class; $ ServerIdHolder-> Id = 5; $ Ch = curl_init (); Curl_setopt ($ c, CURLOPT_URL, 'http://www.whatever.com'); Curl_setopt ($ ch, CURLOPT_WRITEFUNCTION, use function ($ ch, $ string) or ($ serverIdHolder) {read read callback ($ ch, $ string, $ serverIdolder-> id;)}}; curl_exec ($ ch); function Pdhenkelbak ($ ch, $ string, $ serverid) {echo "server #", $ serverid, "|", $ string; return Streln ($ string);}
Comments
Post a Comment