cURL curl_multi_exec
(PHP 5, PHP 7, PHP 8)
curl_multi_exec — 현재 cURL 핸들의 하위 연결 실행
설명
curl_multi_exec(CurlMultiHandle $multi_handle
, int &$still_running
): int
스택의 각 핸들을 처리합니다. 핸들이 데이터를 읽거나 써야 하는지 여부에 관계없이 이 메서드를 호출할 수 있습니다.
매개변수
multi_handle
- curl_multi_init()에서 반환된 cURL 다중 핸들입니다.
still_running
- 작업이 아직 실행 중인지 여부를 알려주는 플래그에 대한 참조입니다.
반환 값
cURL 사전 정의 상수에 정의된 cURL 코드입니다.
메모: 이것은 전체 멀티 스택에 관한 오류만 반환합니다. 이 함수가 CURLM_OK
를 반환하더라도 개별 전송에서 여전히 문제가 발생했을 수 있습니다.
변경 로그
버전 | 설명 |
---|---|
8.0.0 | multi_handle 은 이제 CurlMultiHandle 인스턴스를 예상합니다. 이전에는 리소스가 필요했습니다. |
Examples
예제 #1 curl_multi_exec() 예제
이 예제는 두 개의 cURL 핸들을 생성하여 다중 핸들에 추가하고 비동기적으로 처리합니다.
<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://example.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
//execute the multi handle
do {
$status = curl_multi_exec($mh, $active);
if ($active) {
// Wait a short time for more activity
curl_multi_select($mh);
}
} while ($active && $status == CURLM_OK);
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
?>
기타
- curl_multi_init() - 새 cURL 다중 핸들을 반환합니다.
- curl_multi_select() - 모든 curl_multi 연결에서 활동을 기다립니다.
- curl_exec() - cURL 세션 수행