Swerve
Examples
Every example by topic, with the page it belongs to.
Request handlers#
ClientRequest– Read the request, write the responseClientRequestClientRequest::sendResponseHeaders– An interim 103 and a final 201ClientRequest::flush– Put the head on the wire before the workClientRequest::sendFile– Send part of a fileClientRequest::end– Trailers after a chunked bodyHeadersSentException– A status after the body beganFormBody– The fields of a url-encoded formFormBody::for– Which requests have a formFormBody::files– An uploaded fileFormBody::input– The raw bytes after parsingRequestBody– Read a body as it arrivesRequestHandler– Hello, worldRequestHandlerServerInterfaceStaticFiles– Files, and the application for the restStaticFilesStaticFiles::__constructStaticFiles::wrap– Ranges, revalidation, and no PHP sourcesSwerve– Messages and the cache within one processSwerve
WebSockets and SSE#
ServerSentEvents– An event streamServerSentEventsServerSentEvents::lastEventId– Resume after the last event seenServerSentEvents::send– Event names, ids and retryServerSentEvents::sendServerSentEvents::comment– Keep-alive commentsWebSocket– An echo serverWebSocketWebSocketWebSocket::from– Listen to messages, push from a subscriptionWebSocket::fromWebSocket::accept– Read with receive() and close yourselfWebSocket::acceptWebSocket::handshake– Decisions for four requestsWebSocket::upgrade– An adapter's upgradeWebSocket::run– After a 101 of your ownWebSocket::receiveWebSocket::sendWebSocket::sendBinary– A binary messageWebSocket::sendBinaryWebSocket::end– A close code of your ownWebSocket::endWebSocketHandshake– Accepted and refused
Coordination across workers#
Claim– Two handles on one nameClaimClaimClaim::acquire– Wait for the holder to finishClaim::acquireClaim::release– Release before the handle goesOrderedChannel– One order for every subscriberOrderedChannelOrderedChannel::write– Nothing is kept without a subscriberOrderedChannel::writeOrderedChannel::subscribeOrderedChannel::getIterator– Subscribe at the foreachSubscriberLagException– A subscriber that fell behindSubscriberLagExceptionSubscription– A subscription ends with its last referenceSubscriptionSubscription::getIteratorSwerve::publish– Every subscriber gets every messageSwerve::publishSwerve::publishRaw– A WebSocket handler forwards binary frames to the other workersSwerve::publishRawSwerve::subscribe– What a subscriber receives for each kind of valueSwerve::subscribe– A heartbeat for keep-alivesSwerve::subscribeSwerve::claim– Only one runs the reportSwerve::claimSealedObject– A read-only messageSealedObjectSealedObject::seal– Seal a decoded value
Resource management#
Cache– Set, get and expire valuesCacheCache::getCache::getMultipleCache::has– A stored null and a missing keyCache::setCache::setMultiple– Several values with one ttlCache::delete– Delete one key, or severalCache::clear– Empty the cacheCacheKeyException– Keys the cache refusesCacheKeyExceptionSwerve::cache– Load once, then read from the cacheSwerve::cache
Production#
StopReason– Tell the client whySwerve::log– The logger before swerve sets oneSwerve::logSwerve::setLog– Log through a PSR-3 logger of your ownSwerve::setLogSwerve::draining– False while serving, true once the drain beginsSwerve::drainingSwerve::onShutdown– Close a WebSocket with a reason when the server stopsSwerve::onShutdownSwerve::awaitShutdown– Wait with a timeoutSwerve::awaitShutdownSwerve::iniSwerve::onWorkerStartSwerve::getVersion– The installed versionWorkerStoppingException– Clean up when the worker stops