
SwooleCoroutineHttpClient의 getDefer 메서드는 비동기 HTTP 요청을 처리하는 데 사용됩니다. 반환 값은 요청의 결과 또는 에러를 나타냅니다.
getDefer를 사용하여 요청을 취소하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient();
$client->getDefer('http://example.com')->then(function ($response) {
// 요청이 성공했을 때 처리할 코드
})->catch(function ($e) {
// 요청이 실패했을 때 처리할 코드
});
// 요청을 취소하려면 $client->getDefer('http://example.com')->cancel()을 호출합니다.
getDefer를 사용하여 여러 요청을 처리할 때, 요청의 순서를 지정하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient();
$client->getDefer('http://example.com')->then(function ($response) {
// 요청 1이 완료되었을 때 처리할 코드
})->getDefer('http://example.com')->then(function ($response) {
// 요청 2가 완료되었을 때 처리할 코드
})->getDefer('http://example.com')->then(function ($response) {
// 요청 3이 완료되었을 때 처리할 코드
});
요청이 완료될 때까지 대기하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient();
$client->getDefer('http://example.com')->then(function ($response) {
// 요청이 완료되었을 때 처리할 코드
});
// 요청이 완료될 때까지 대기하려면 $client->getDefer('http://example.com')->wait()을 호출합니다.
요청이 완료될 때까지 대기하는 메서드는 Swoole 4.4.0 이상에서만 사용할 수 있습니다.
2025-06-06 10:18