
SwooleHttpClient::set 함수의 options에 대한 이해를 위해 설명드리겠습니다.
CURLINFO_HEADER_OUT 옵션을 사용하여 HTTP 요청 헤더를 출력하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$client = new SwooleHttpClient('example.com', 80);
$client->set(array(
CURLOPT_HEADER => 1,
CURLOPT_HEADERFUNCTION => function($ch, $header) use ($client) {
echo $header . "n";
return strlen($header);
},
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$client->connect();
$client->send();
$response = $client->recv();
$client->close();
이 옵션을 사용하면 HTTP 요청 헤더를 echo 문구를 통해 출력할 수 있습니다.
HTTP 요청 헤더를 저장하고 나중에 출력하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$client = new SwooleHttpClient('example.com', 80);
$client->set(array(
CURLOPT_HEADER => 1,
CURLOPT_HEADERFUNCTION => function($ch, $header) use ($client) {
$client->header = $header;
return strlen($header);
},
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$client->connect();
$client->send();
$client->close();
echo $client->header;
이 옵션을 사용하면 HTTP 요청 헤더를 변수에 저장하고 나중에 출력할 수 있습니다.
2025-05-27 20:31