참고
- php.net cURL Manual
- stackoverflow asynchronous-php-calls
- Maintaining PHP session when using CURL.
- Easy Parallel Processing in PHP
$mch = curl_multi_init(); session_write_close(); // curl 세션 정보공유를 위해서 필요함. $data = "Key=Val or Arr"; $pickup = "http://mypickup.kr/class/method/"; $cookie = Array(); foreach($_COOKIE AS $key => $val) $cookie[] = $key.'='.$val; $cookie = implode(';', $cookie).'; path=/'; foreach($arr AS $key => $val){ $ch_{$val} = curl_init(); curl_setopt($ch_{$val}, CURLOPT_TIMEOUT, 30); curl_setopt($ch_{$val}, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch_{$val}, CURLOPT_COOKIE, $cookie); // 세션 유지를위해서 꼭 필요한 내용 curl_setopt($ch_{$val}, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch_{$val}, CURLOPT_URL, $pickup); curl_setopt($ch_{$val}, CURLOPT_HEADER, 0); curl_setopt($ch_{$val}, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch_{$val}, CURLOPT_POST, 1); curl_setopt($ch_{$val}, CURLOPT_POSTFIELDS, $data); curl_multi_add_handle($mch, $ch_{$val}); } $active = NULL; do{ $mrs = curl_multi_exec($mch, $active); } while ($mrs == CURLM_CALL_MULTI_PERFORM); while ($active && $mrs == CURLM_OK) { if (curl_multi_select($mch) != -1) { do { $mrs = curl_multi_exec($mch, $active); } while ($mrs == CURLM_CALL_MULTI_PERFORM); } } foreach($this->data['sns'] AS $key => $val){ if(! empty($ch_{$val})){ $rs = curl_multi_getcontent($ch_{$val}); curl_multi_remove_handle($mch, $ch_{$val}); if(! empty($rs) && is_array(json_decode($rs, TRUE))){ $print = array_merge($this->data, json_decode($rs, TRUE) ); } } } curl_multi_close($mch);
반응형
'lang > php' 카테고리의 다른 글
ubuntu apm 설치 (0) | 2010.10.21 |
---|---|
facebook API Quick Guide (CodeIgniter) (0) | 2010.10.15 |
curl "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL" (0) | 2010.09.30 |
php integer 크기 (0) | 2010.09.28 |
php hiphop 컴파일 설치 (0) | 2010.09.20 |