cURL curl_share_setopt

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

curl_share_setopt — cURL 공유 핸들에 대한 옵션 설정


설명

curl_share_setopt(CurlShareHandle $share_handle, int $option, mixed $value): bool

주어진 cURL 공유 핸들에 대한 옵션을 설정합니다.


매개변수

share_handle
curl_share_init()에서 반환된 cURL 공유 핸들입니다.
option
Option 설명
CURLSHOPT_SHARE 공유해야 하는 데이터 유형을 지정합니다.
CURLSHOPT_UNSHARE 더 이상 공유되지 않을 데이터 유형을 지정합니다.
value
Value 설명
CURL_LOCK_DATA_COOKIE 쿠키 데이터를 공유합니다.
CURL_LOCK_DATA_DNS DNS 캐시를 공유합니다. cURL 다중 핸들을 사용할 때 동일한 다중 핸들에 추가된 모든 핸들은 기본적으로 DNS 캐시를 공유합니다.
CURL_LOCK_DATA_SSL_SESSION SSL 세션 ID를 공유하여 동일한 서버에 다시 연결할 때 SSL 핸드셰이크에 소요되는 시간을 줄입니다. SSL 세션 ID는 기본적으로 동일한 핸들 내에서 재사용됩니다.

반환 값

성공하면 true를, 실패하면 false를 반환합니다.


변경 로그

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

Examples

예제 #1 curl_share_setopt() 예제

이 예에서는 cURL 공유 핸들을 만들고 여기에 두 개의 cURL 핸들을 추가한 다음 쿠키 데이터 공유와 함께 실행합니다.

                  
<?php
// Create cURL share handle and set it to share cookie data
$sh = curl_share_init();
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);

// Initialize the first cURL handle and assign the share handle to it
$ch1 = curl_init("http://example.com/");
curl_setopt($ch1, CURLOPT_SHARE, $sh);

// Execute the first cURL handle
curl_exec($ch1);

// Initialize the second cURL handle and assign the share handle to it
$ch2 = curl_init("http://php.net/");
curl_setopt($ch2, CURLOPT_SHARE, $sh);

// Execute the second cURL handle
//  all cookies from $ch1 handle are shared with $ch2 handle
curl_exec($ch2);

// Close the cURL share handle
curl_share_close($sh);

// Close the cURL handles
curl_close($ch1);
curl_close($ch2);
?>