cURL curl_multi_add_handle

(PHP 5, PHP 7, PHP 8)

curl_multi_add_handle — cURL 다중 핸들에 일반 cURL 핸들 추가


설명

curl_multi_add_handle(CurlMultiHandle $multi_handle, CurlHandle $handle): int

멀티 핸들 multi_handlehandle 핸들을 추가합니다.


매개변수

multi_handle
curl_multi_init()에서 반환된 cURL 다중 핸들입니다.
handle
curl_init()에서 반환된 cURL 핸들입니다.

반환 값

성공하면 0을 반환하거나 CURLM_XXX 오류 코드 중 하나를 반환합니다.


변경 로그

버전 설명
8.0.0 multi_handle은 이제 CurlMultiHandle 인스턴스를 예상합니다. 이전에는 리소스가 필요했습니다.
8.0.0 handle은 이제 CurlHandle 인스턴스를 예상합니다. 이전에는 리소스가 필요했습니다.

Examples

예제 #1 curl_multi_add_handle() 예제

이 예제는 두 개의 cURL 핸들을 생성하여 다중 핸들에 추가하고 비동기적으로 처리합니다.

                  
<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://www.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) {
        curl_multi_select($mh);
    }
} while ($active && $status == CURLM_OK);

//close all the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
?>
                  
                

기타