라이브러리
[PHP] EventHttp::__construct - EventHttp 객체(HTTP 서버)를 구성합니다.
EventHttp::__construct
EventHttp는 PHP의 EventLoop를 사용하여 HTTP 서버를 구현하는 클래스입니다. EventHttp::__construct는 EventHttp 객체를 초기화하는 생성자 메서드입니다.
# 생성자 매개변수
EventHttp::__construct의 생성자 매개변수는 다음과 같습니다.
* `$server`: HTTP 서버를 구현하는 클래스입니다. 기본값은 `EventHttp`입니다.
* `$port`: HTTP 서버가 listens할 포트 번호입니다. 기본값은 80입니다.
* `$mode`: HTTP 서버의 모드입니다. 기본값은 `EventHttp::MODE_DEFAULT`입니다.
* `$workerCount`: HTTP 서버가 사용할 워커 수입니다. 기본값은 1입니다.
* `$workerSize`: HTTP 서버가 사용할 워커 크기입니다. 기본값은 128KB입니다.
* `$maxRequestSize`: HTTP 요청의 최대 크기입니다. 기본값은 2MB입니다.
* `$maxRequestBodySize`: HTTP 요청 본문의 최대 크기입니다. 기본값은 2MB입니다.
* `$maxResponseSize`: HTTP 응답의 최대 크기입니다. 기본값은 2MB입니다.
* `$maxKeepAliveRequests`: HTTP Keep-Alive의 최대 요청 수입니다. 기본값은 100입니다.
* `$maxKeepAliveTimeout`: HTTP Keep-Alive의 최대 타임아웃입니다. 기본값은 60초입니다.
* `$sslOptions`: HTTPS 서버를 구현할 때 사용하는 SSL 옵션입니다. 기본값은 `null`입니다.
# 예제
EventHttp::__construct를 사용하여 HTTP 서버를 구현하는 예제는 다음과 같습니다.
#hostingforum.kr
php
use SwooleHttpServer;
class MyHttpServer extends EventHttp
{
public function __construct()
{
parent::__construct([
'server' => 'EventHttp',
'port' => 8080,
'mode' => EventHttp::MODE_DEFAULT,
'workerCount' => 1,
'workerSize' => 128 * 1024,
'maxRequestSize' => 2 * 1024 * 1024,
'maxRequestBodySize' => 2 * 1024 * 1024,
'maxResponseSize' => 2 * 1024 * 1024,
'maxKeepAliveRequests' => 100,
'maxKeepAliveTimeout' => 60,
'sslOptions' => [
'local_cert' => '/path/to/cert.pem',
'local_key' => '/path/to/key.pem',
],
]);
}
public function onRequest(Event $event)
{
$request = $event->request;
$response = $event->response;
$response->status = 200;
$response->header('Content-Type', 'text/plain');
$response->end('Hello, World!');
}
}
$server = new MyHttpServer();
$server->start();
이 예제에서는 EventHttp::__construct를 사용하여 HTTP 서버를 구현하고, `onRequest` 이벤트 핸들러를 구현하여 HTTP 요청을 처리합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.