
দুর্দান্ত curl_multi_exec
cURL সম্পর্কে পিএইচপি প্রোগ্রামাররা কমবেশি জানেন। কমপক্ষে এইটা সবাই জানি যে, এই জিনিস কোড থেকে HTTP রিকোয়েস্টগুলো করার জন্য ব্যবহৃত হয় এবং রিকোয়েস্টেড URL থেকে রেসপন্সটা নিয়ে আসে। খুব সাম্প্রতিক ফুরফুরে এক হেমন্তের সন্ধ্যায় একটা কাজে বসে দেখলাম আমার একবারে একাধিক cURL রিকোয়েস্ট করতে হবে। স্বাভাবিক ভাবে যেটা মাথায় এলো সেটা হচ্ছে, একটা লুপের মধ্যে একটা একটা করে cURL রিকোয়েস্টকে execute করার কথা! চলুন তো দেখি সেই ‘উর্বর’ কোডটা কেমন হতোঃ
$result=array();
foreach ($students as $i => $student) {
$data = array(
'username'=>"username",
'password'=>"**********",
'number'=> $student->number,
'message'=>$student->message
);
$url= 'http://myapiurl.com/api';
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result[] = curl_exec($ch);
curl_close($ch);
}এখানে দেখা যাচ্ছে আমি কিছু শিক্ষার্থীর অভিভাবকের মোবাইলে SMS পাঠাতে চাচ্ছি। এখন যদি আমার এই লুপে শিক্ষার্থী সংখ্যা 50 জন হয় তাহলে একবার রিকোয়েস্টে প্রাপ্ত গড় Response Time 50X গুণ হবে! অর্থাৎ সবগুলো রিকোয়েস্টের সমষ্টিগত সময় হবে পুরো রিকোয়েস্টটির রেসপন্স টাইম! এবং ভয়াবহভাবে এটি HTTP এর যেকোন Timeout Error (408, 504 ইত্যাদি)-এর স্বীকার হতে পারে! ফলশ্রুতিতে উপর্যুক্ত কোডটি একটি ‘নিম্নমানের’ কোড হিসেবে বিবেচিত হবে।
কিন্তু আমার তো এক রিকোয়েস্টেই সব SMS গুলো পাঠাতে হবে। একটু ঘাটাঘাটি করে দেখলাম, cURL এর মাল্টিপল রিকোয়েস্ট হ্যান্ডেল করার মতো একটি মেথড আছেঃ curl_multi_exec
এই অসাধারণ ফাংশন curl_multi_exec দিয়ে পুরো কোডটাকে চলুন রিফ্যাক্টর করে দেখি-
$url = "http://myapiurl.com/api";
// array of curl handles
$multiCurl = array();
// data to be returned
$result = array();
// multi handle, a parameter of curl_multi_exec
$mh = curl_multi_init();
// sms data
$smsdata = [];
foreach ($students as $i => $student) {
$smsdata[$i] = array(
'username'=>"username",
'password'=>"**********",
'number'=> $student->number,
'message'=>$student->message
);
$multiCurl[$i] = curl_init(); // Initialize cURL
curl_setopt($multiCurl[$i], CURLOPT_URL, $url);
curl_setopt($multiCurl[$i], CURLOPT_HEADER, 0);
curl_setopt($multiCurl[$i], CURLOPT_POSTFIELDS, http_build_query($smsdata[$i]));
curl_setopt($multiCurl[$i], CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($mh, $multiCurl[$i]);
}
$index=null;
do {
curl_multi_exec($mh, $index);
} while($index > 0);
// get content and remove handles
foreach($multiCurl as $k => $ch) {
$result[$k] = curl_multi_getcontent($ch);
curl_multi_remove_handle($mh, $ch);
}
curl_multi_close($mh);এই অংশটি ব্যবহার করে আমি সত্যিকারের কিছু মোবাইল নম্বর দিয়ে টেস্ট করে দেখলাম রেসপন্স টাইম উল্লেখযোগ্যভাবে হ্রাস পেয়েছে। এবং কোন সিঙ্গেল cURL রিকোয়েস্ট-এর জন্য Timeout Error হবার কারণও নেই!
gcYr9T4weXO
sZPFGi1nqaw
mgPEnY8O5wy
xVdD8Obcapq
YafDTKzdyQ7
REUthhOJStJ
3i8udT0iIKH
1iIVMSfF21X
T5sGjvLRtEZ
lZlHHqdic8r
T5VSUUlGauN
AQX0jLVTj6W
wnVs6SZLNCL
BjV0VK8qjdK
fZvE2rBicFN
27psX2055jG
zQXrEjkzn16
KgMxSuxAxGA
4KYW41DtkpD
sQfKHUK03TA
c5kyrtoqzMD
JlfVsUvycF9
YpEcyjMcHuh
MyQw6sbVxNO
ISiwfZveIKu
rhBuntGGa3c
x4I4Y6uZuUj
qVlht74Ban5
He4kmE7IdyW
7ONES0bHaaE
PvFBwWJHCZW
JKrbV9zGQFt
dVLBrDE8zfO
Wc0GlResw9i
Sprunki Game truly elevates the Incredibox experience with its rich soundscapes and creative freedom. As a fan of musical innovation, I love how it blends accessibility with depth-perfect for both casual and serious creators. Check it out at Sprunki Game!
Hey folks! Heard about 88lotterylogin? Thinking about giving it a shot. Anyone had any luck with them? I’m always on the hunt for a good lottery site. Fingers crossed! Check them out here: 88lotterylogin
Been hearing a lot about yo88vina lately. Thinking about giving it a shot. Anything special I should know before I dive in? Is it worth the hype?
Hoki108slottm has a few slots I hadn’t seen before, so that was a bonus. Not a bad spot for spinning if you’re bored. Have a look: hoki108slottm
Just tried out zz777br1, and gotta say, it’s pretty slick! The layout is clean, and I found some games I really dig. Definitely worth checking out, guys! Give it a go at zz777br1.
Joygame777 is okay. Not the best, but it’s something to do. If you’re bored, why not take a look? Check it out here: joygame777
Heard about bn55com from a friend, checking it out now. Hope it’s as good as they say! Definitely clicking this bn55com link to see what all the fuss is about.
Alright, time to create an account on baji666login. Fingers crossed it’s a smooth process and I can get straight into the action. Here’s the baji666login link for anyone else joining.
OG777 Official Site: Fast Login, Easy Register & Slot Link. Download the OG777 App for the Best Online Casino Experience in the Philippines. Join the OG777 official site, the #1 online casino in the Philippines. Experience fast og777 login, easy og777 register, and the latest og777 slot link. Download the og777 app today for a premium gaming experience and big wins! visit: og777
Dreamjilicasino, huh? Gave it a shot and it wasn’t too shabby. Games were alright and deposit was easy. I’d recommend checking it out if you are looking to try your luck! Check this page out dreamjilicasino
Thinking about signing up for OKBet.com. Easy process? Good promos? Lemme know what you think before I jump in! Easy sign up?: okbet.com sign up
Figuring out how to play scatter? It’s easier than you think! Check out how to play scatter for some helpful guides and start raking in those wins!
Alright, so I was looking for Plot777 app download and found this site. Seems legit. Gonna check it out and see if it’s the real deal. Hope it’s not another fake! Check it out here: plot777 app download
Watching live games on Nesine is awesome, especially with the in-play betting options. Makes things way more exciting! Check it out: nesine canlı.
Okay, about to hit up the 30 jili login and see what’s what. Any recommendations on what games to try first? Hit me with your best picks!