Event
Event (libevent 기반 이벤트 확장)
I/O, 시간, 시그널 기반 이벤트를 효율적으로 스케줄링하고 싶을 때 쓰는 확장이에요. 사용 가능한 최선의 I/O 알림 메커니즘을 활용해 이벤트를 처리하며, libevent를 PHP 인프라로 포팅한 거예요. 비동기·이벤트 기반 프로그래밍이 필요할 때 씁니다.
출처: Event
본문
소개
이 확장은 특정 플랫폼에서 사용 가능한 최선의 I/O 알림 메커니즘을 이용해 I/O, 시간, 시그널 기반 이벤트를 효율적으로 스케줄링하는 확장이에요. libevent를 PHP 인프라에 포팅한 거죠.
기억해 둘 버전 관련 내용이 몇 가지 있어요.
- Windows 지원은 event-1.9.0부터 도입됐어요.
- 버전 1.0.0은 새로운 객체 지향 API(하위 호환을 깨는 변경)를 도입하고, HTTP, DNS, OpenSSL, 이벤트 리스너를 포함한 libevent 2+를 지원해요.
- event-1.0.0 이상은 이전 버전과 호환되지 않아요.
주요 클래스 흐름은 EventBase(이벤트 루프/베이스), Event(개별 이벤트), EventBuffer(버퍼), EventBufferEvent(버퍼 이벤트) 등으로 구성돼요. 네트워크 프로그래밍에서 비동기 I/O를 처리할 때 특히 유용해요.
클래스 참조
Event — The Event class
Event::add— Makes event pendingEvent::addSignal— Alias of Event::addEvent::addTimer— Alias of Event::addEvent::__construct— Constructs Event objectEvent::del— Makes event non-pendingEvent::delSignal— Alias of Event::delEvent::delTimer— Alias of Event::delEvent::free— Make event non-pending and free resources allocated for this eventEvent::getSupportedMethods— Returns array of the names of the methods supported in this version of LibeventEvent::pending— Detects whether event is pending or scheduledEvent::set— Re-configures eventEvent::setPriority— Set event priorityEvent::setTimer— Re-configures timer eventEvent::signal— Constructs signal event objectEvent::timer— Constructs timer event object
EventBase — The EventBase class
EventBase::__construct— Constructs EventBase objectEventBase::dispatch— Dispatch pending eventsEventBase::exit— Stop dispatching eventsEventBase::free— Free resources allocated for this event baseEventBase::getFeatures— Returns bitmask of features supportedEventBase::getMethod— Returns event method in useEventBase::getTimeOfDayCached— Returns the current event base timeEventBase::gotExit— Checks if the event loop was told to exitEventBase::gotStop— Checks if the event loop was told to exitEventBase::loop— Dispatch pending eventsEventBase::priorityInit— Sets number of priorities per event baseEventBase::reInit— Re-initialize event base (after a fork)EventBase::stop— Tells event_base to stop dispatching events
EventBuffer — The EventBuffer class
EventBuffer::add— Append data to the end of an event bufferEventBuffer::addBuffer— Move all data from a buffer provided to the current instance of EventBufferEventBuffer::appendFrom— Moves the specified number of bytes from a source buffer to the end of the current bufferEventBuffer::__construct— Constructs EventBuffer objectEventBuffer::copyout— Copies out specified number of bytes from the front of the bufferEventBuffer::drain— Removes specified number of bytes from the front of the buffer without copying it anywhereEventBuffer::enableLocking— DescriptionEventBuffer::expand— Reserves space in bufferEventBuffer::freeze— Prevent calls that modify an event buffer from succeedingEventBuffer::lock— Acquires a lock on bufferEventBuffer::prepend— Prepend data to the front of the bufferEventBuffer::prependBuffer— Moves all data from source buffer to the front of current bufferEventBuffer::pullup— Linearizes data within buffer and returns its contents as a stringEventBuffer::read— Read data from an evbuffer and drain the bytes readEventBuffer::readFrom— Read data from a file onto the end of the bufferEventBuffer::readLine— Extracts a line from the front of the bufferEventBuffer::search— Scans the buffer for an occurrence of a stringEventBuffer::searchEol— Scans the buffer for an occurrence of an end of lineEventBuffer::substr— Subtracts a portion of the buffer dataEventBuffer::unfreeze— Re-enable calls that modify an event bufferEventBuffer::unlock— Releases lock acquired by EventBuffer::lockEventBuffer::write— Write contents of the buffer to a file or socket
EventBufferEvent — The EventBufferEvent class
EventBufferEvent::close— Closes file descriptor associated with the current buffer eventEventBufferEvent::connect— Connect buffer event's file descriptor to given address or UNIX socketEventBufferEvent::connectHost— Connects to a hostname with optionally asynchronous DNS resolvingEventBufferEvent::__construct— Constructs EventBufferEvent objectEventBufferEvent::createPair— Creates two buffer events connected to each otherEventBufferEvent::disable— Disable events read, write, or both on a buffer eventEventBufferEvent::enable— Enable events read, write, or both on a buffer eventEventBufferEvent::free— Free a buffer eventEventBufferEvent::getDnsErrorString— Returns string describing the last failed DNS lookup attemptEventBufferEvent::getEnabled— Returns bitmask of events currently enabled on the buffer eventEventBufferEvent::getInput— Returns underlying input buffer associated with current buffer eventEventBufferEvent::getOutput— Returns underlying output buffer associated with current buffer eventEventBufferEvent::read— Read buffer's dataEventBufferEvent::readBuffer— Drains the entire contents of the input buffer and places them into bufEventBufferEvent::setCallbacks— Assigns read, write and event(status) callbacksEventBufferEvent::setPriority— Assign a priority to a buffereventEventBufferEvent::setTimeouts— Set the read and write timeout for a buffer eventEventBufferEvent::setWatermark— Adjusts read and/or write watermarksEventBufferEvent::sslError— Returns most recent OpenSSL error reported on the buffer eventEventBufferEvent::sslFilter— Create a new SSL buffer event to send its data over another buffer eventEventBufferEvent::sslGetCipherInfo— Returns a textual description of the cipherEventBufferEvent::sslGetCipherName— Returns the current cipher name of the SSL connectionEventBufferEvent::sslGetCipherVersion— Returns version of cipher used by current SSL connectionEventBufferEvent::sslGetProtocol— Returns the name of the protocol used for current SSL connectionEventBufferEvent::sslRenegotiate— Tells a bufferevent to begin SSL renegotiationEventBufferEvent::sslSocket— Creates a new SSL buffer event to send its data over an SSL on a socketEventBufferEvent::write— Adds data to a buffer event's output bufferEventBufferEvent::writeBuffer— Adds contents of the entire buffer to a buffer event's output buffer
EventConfig — The EventConfig class
EventConfig::avoidMethod— Tells libevent to avoid specific event methodEventConfig::__construct— Constructs EventConfig objectEventConfig::requireFeatures— Enters a required event method feature that the application demandsEventConfig::setFlags— Sets one or more flags that configure how the eventual EventBase will be initializedEventConfig::setMaxDispatchInterval— Prevents priority inversion
EventDnsBase — The EventDnsBase class
EventDnsBase::addNameserverIp— Adds a nameserver to the DNS baseEventDnsBase::addSearch— Adds a domain to the list of search domainsEventDnsBase::clearSearch— Removes all current search suffixesEventDnsBase::__construct— Constructs EventDnsBase objectEventDnsBase::countNameservers— Gets the number of configured nameserversEventDnsBase::loadHosts— Loads a hosts file (in the same format as /etc/hosts) from hosts fileEventDnsBase::parseResolvConf— Scans the resolv.conf-formatted fileEventDnsBase::setOption— Set the value of a configuration optionEventDnsBase::setSearchNdots— Set the 'ndots' parameter for searches
EventHttp — The EventHttp class
EventHttp::accept— Makes an HTTP server accept connections on the specified socket stream or resourceEventHttp::addServerAlias— Adds a server alias to the HTTP server objectEventHttp::bind— Binds an HTTP server on the specified address and portEventHttp::__construct— Constructs EventHttp object (the HTTP server)EventHttp::removeServerAlias— Removes server aliasEventHttp::setAllowedMethods— Sets which HTTP methods are supported in requests accepted by this server, and passed to user callbacksEventHttp::setCallback— Sets a callback for specified URIEventHttp::setDefaultCallback— Sets default callback to handle requests that are not caught by specific callbacksEventHttp::setMaxBodySize— Sets maximum request body sizeEventHttp::setMaxHeadersSize— Sets maximum HTTP header sizeEventHttp::setTimeout— Sets the timeout for an HTTP request
EventHttpConnection — The EventHttpConnection class
EventHttpConnection::__construct— Constructs EventHttpConnection objectEventHttpConnection::getBase— Returns event base associated with the connectionEventHttpConnection::getPeer— Gets the remote address and port associated with the connectionEventHttpConnection::makeRequest— Makes an HTTP request over the specified connectionEventHttpConnection::setCloseCallback— Set callback for connection closeEventHttpConnection::setLocalAddress— Sets the IP address from which HTTP connections are madeEventHttpConnection::setLocalPort— Sets the local port from which connections are madeEventHttpConnection::setMaxBodySize— Sets maximum body size for the connectionEventHttpConnection::setMaxHeadersSize— Sets maximum header sizeEventHttpConnection::setRetries— Sets the retry limit for the connectionEventHttpConnection::setTimeout— Sets the timeout for the connection
EventHttpRequest — The EventHttpRequest class
EventHttpRequest::addHeader— Adds an HTTP header to the headers of the requestEventHttpRequest::cancel— Cancels a pending HTTP requestEventHttpRequest::clearHeaders— Removes all output headers from the header list of the requestEventHttpRequest::closeConnection— Closes associated HTTP connectionEventHttpRequest::__construct— Constructs EventHttpRequest objectEventHttpRequest::findHeader— Finds the value belonging to a headerEventHttpRequest::free— Frees the object and removes associated eventsEventHttpRequest::getBufferEvent— Returns EventBufferEvent objectEventHttpRequest::getCommand— Returns the request command(method)EventHttpRequest::getConnection— Returns EventHttpConnection objectEventHttpRequest::getHost— Returns the request hostEventHttpRequest::getInputBuffer— Returns the input bufferEventHttpRequest::getInputHeaders— Returns associative array of the input headersEventHttpRequest::getOutputBuffer— Returns the output buffer of the requestEventHttpRequest::getOutputHeaders— Returns associative array of the output headersEventHttpRequest::getResponseCode— Returns the response codeEventHttpRequest::getUri— Returns the request URIEventHttpRequest::removeHeader— Removes an HTTP header from the headers of the requestEventHttpRequest::sendError— Send an HTML error message to the clientEventHttpRequest::sendReply— Send an HTML reply to the clientEventHttpRequest::sendReplyChunk— Send another data chunk as part of an ongoing chunked replyEventHttpRequest::sendReplyEnd— Complete a chunked reply, freeing the request as appropriateEventHttpRequest::sendReplyStart— Initiate a chunked reply
EventListener — The EventListener class
EventListener::__construct— Creates new connection listener associated with an event baseEventListener::disable— Disables an event connect listener objectEventListener::enable— Enables an event connect listener objectEventListener::getBase— Returns event base associated with the event listenerEventListener::getSocketName— Retrieves the current address to which the listener's socket is boundEventListener::setCallback— The setCallback purposeEventListener::setErrorCallback— Set event listener's error callback
EventSslContext — The EventSslContext class
EventSslContext::__construct— Constructs an OpenSSL context for use with Event classes
EventUtil — The EventUtil class
EventUtil::__construct— The abstract constructorEventUtil::getLastSocketErrno— Returns the most recent socket error numberEventUtil::getLastSocketError— Returns the most recent socket errorEventUtil::getSocketFd— Returns numeric file descriptor of a socket, or streamEventUtil::getSocketName— Retrieves the current address to which the socket is boundEventUtil::setSocketOption— Sets socket optionsEventUtil::sslRandPoll— Generates entropy by means of OpenSSL's RAND_poll()
예외 클래스
EventException— The EventException class
더 알아보기
- 이벤트 루프의 중심이 되는
EventBase를 만들고, 그 위에Event나EventBufferEvent를 얹어 비동기 I/O를 처리하는 구조예요. 처음엔 '이벤트 언제든 pending/비pending 상태가 바뀐다'는 흐름을 이해하는 게 중요해요. - 버전 주의사항을 꼭 확인하세요. 1.0.0 이후는 이전 버전과 호환되지 않고, Windows 지원은 1.9.0부터예요.