
SwooleCoroutineHttpClient::execute 함수는 Coroutine을 사용하여 HTTP 요청을 보내는 함수입니다.
이 함수의 파라미터 중 'options'는 HTTP 요청에 대한 옵션을 지정하는 배열입니다.
'options'의 'timeout' 부분은 HTTP 요청이 완료되기까지의 최대 시간을 초 단위로 지정합니다.
이 값이 0인 경우, HTTP 요청이 완료되기까지의 시간이 제한되지 않습니다.
다음은 SwooleCoroutineHttpClient::execute 함수의 예제 코드입니다.
#hostingforum.kr
php
use SwooleHttpClient;
$client = new Client('http://example.com');
$client->setHeaders([
'User-Agent' => 'Swoole',
]);
$coroutine = new SwooleCoroutine();
$coroutine->start(function () use ($client) {
$result = $client->execute('/path', [], [
'timeout' => 5, // 5초 이내에 HTTP 요청이 완료되어야 함
]);
var_dump($result);
});
이 예제 코드에서는 'timeout' 옵션을 5초로 지정하여 HTTP 요청이 완료되기까지의 시간이 5초로 제한됩니다.
만약 'timeout' 옵션이 0인 경우, HTTP 요청이 완료되기까지의 시간이 제한되지 않습니다.
#hostingforum.kr
php
$coroutine = new SwooleCoroutine();
$coroutine->start(function () use ($client) {
$result = $client->execute('/path', [], [
'timeout' => 0, // HTTP 요청이 완료되기까지의 시간이 제한되지 않음
]);
var_dump($result);
});
2025-08-02 01:34