Cloud

Reference for the Cloud module: register cloud vendors and services, drive container start and stop queues, and process container heartbeats. Containers run on servers, are addressed by a service identifier and a container reference, and report back over an admin-token authenticated heartbeat endpoint.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes

Cloud

The primary class: handles container heartbeat requests posted to the admin endpoint.

Functions

HandleHeartbeat

Cloud::HandleHeartbeat(): void

Handle a container heartbeat request. Called from the app before the web server runs; it responds only to POST requests whose URI contains /cloud/admin/heartbeat, authenticates the admin token from the Authorization header, stores the heartbeat, and returns the JSON response. Other requests return without acting.

Returns void

CloudContainer

Reads a container's status as human-readable text.

StatusHumanReadable

CloudContainer::StatusHumanReadable($container): string

The human-readable status text for a container, such as Starting, Running, Stopping, Stopped or Error.

NameTypeDescription
$containerCloudContainerData|objectA container object with a status property.

Returns string The status text.

CloudContainerChannelConfig

Register handlers for container channel identifiers and read them back. Each handler processes the data from a channel request and returns response data.

Properties

PropertyTypeDescription
CloudContainerChannelConfig::$handlersarrayThe registered handler objects.

AddHandler

CloudContainerChannelConfig::AddHandler(string $channelIdentifier, callable $handler): void

Register a handler for a channel identifier. Throws when a handler is already registered for that identifier.

NameTypeDescription
$channelIdentifierstringThe channel identifier; lowercased before use.
$handlercallableThe function that processes the channel request.

Returns void

GetHandler

CloudContainerChannelConfig::GetHandler(string $channelIdentifier): ?callable

The handler registered for a channel identifier, or null when none is registered.

NameTypeDescription
$channelIdentifierstringThe channel identifier; lowercased before lookup.

Returns ?callable The handler, or null.

CloudContainerCurrentStatusData

Real-time status data for a running container. Fields and constructor, plus JSON conversions.

Properties

PropertyTypeDescription
$status->containerNamestringThe container name (readonly).
$status->statusstringThe container status text (readonly).
$status->image?stringThe image name (readonly).
$status->imageId?stringThe image id (readonly).
$status->createdTimestamp?intWhen the container was created (readonly).
$status->optionalStartedTimestamp?intWhen the container started (readonly).
$status->optionalFinishedTimestamp?intWhen the container finished (readonly).
$status->exitCode?stringThe exit code (readonly).
$status->state?stringThe container state (readonly).
$status->restartCount?stringThe restart count (readonly).
$status->cpuUsage?stringCPU usage (readonly).
$status->memoryUsage?stringMemory usage (readonly).
$status->memoryLimit?stringMemory limit (readonly).
$status->networkRxBytes?stringBytes received (readonly).
$status->networkTxBytes?stringBytes transmitted (readonly).
$status->blockReadBytes?stringBlock bytes read (readonly).
$status->blockWriteBytes?stringBlock bytes written (readonly).
$status->consoleOutput?stringThe console output (readonly).

__construct

new CloudContainerCurrentStatusData(string $containerName, string $status, ?string $image = null, ?string $imageId = null, ?int $createdTimestamp = null, ?int $optionalStartedTimestamp = null, ?int $optionalFinishedTimestamp = null, ?string $exitCode = null, ?string $state = null, ?string $restartCount = null, ?string $cpuUsage = null, ?string $memoryUsage = null, ?string $memoryLimit = null, ?string $networkRxBytes = null, ?string $networkTxBytes = null, ?string $blockReadBytes = null, ?string $blockWriteBytes = null, ?string $consoleOutput = null)

Create current status data for a container.

Returns CloudContainerCurrentStatusData

FromJson

CloudContainerCurrentStatusData::FromJson(string $json): CloudContainerCurrentStatusData

Build current status data from a JSON string, validating the decoded object and its timestamp fields.

NameTypeDescription
$jsonstringThe JSON status object.

Returns CloudContainerCurrentStatusData The status data.

ToJson

CloudContainerCurrentStatusData::ToJson(): string

The status data as a JSON string.

Returns string The JSON representation.

CloudContainerData

Immutable data for a container and the server that hosts it. Fields and constructor only.

Properties

PropertyTypeDescription
$container->idintThe container id (readonly).
$container->vendorIdentifierstringThe vendor identifier (readonly).
$container->serviceIdentifierstringThe service identifier (readonly).
$container->parametersstringThe container parameters (readonly).
$container->statusintThe status, a CloudContainerStatusEnum value (readonly).
$container->visibilityintThe visibility, 0 to 3 (readonly).
$container->containerRef?stringThe container reference (readonly).
$container->serverCloudServerDataThe server hosting the container (readonly).
$container->addedTimestampintWhen the container was added (readonly).
$container->adminToken?stringThe container admin token (readonly).
$container->portNumberintThe port number, 1 to 65535 (readonly).
$container->portAdminTokenstringThe port admin token, a 64-character hex string (readonly).
Functions

__construct

new CloudContainerData(int $id, string $vendorIdentifier, string $serviceIdentifier, string $parameters, int $status, int $visibility, ?string $containerRef, CloudServerData $server, int $addedTimestamp, ?string $adminToken, int $portNumber, string $portAdminToken)

Create container data from its fields and its server.

Returns CloudContainerData

CloudContainerEnvironment

Read environment variables set for a container. Values are base64-encoded by the start script; each reader trims quotes, decodes and validates.

Float

CloudContainerEnvironment::Float(string $name): float

A float environment variable, base64 decoded and parsed. Throws when the variable is missing, fails to decode, or cannot be parsed.

NameTypeDescription
$namestringThe environment variable name.

Returns float The decoded value.

Integer

CloudContainerEnvironment::Integer(string $name): int

An integer environment variable, base64 decoded and parsed. Throws when the variable is missing, fails to decode, or cannot be parsed.

NameTypeDescription
$namestringThe environment variable name.

Returns int The decoded value.

Object

CloudContainerEnvironment::Object(string $name, callable $decodeFunction): mixed

A JSON environment variable, base64 decoded, JSON decoded, then passed to the decode function for validation. Throws when the variable is missing, fails to decode, or is invalid JSON.

NameTypeDescription
$namestringThe environment variable name.
$decodeFunctioncallableCallback that validates and transforms the decoded JSON.

Returns mixed The value returned by the decode function.

OptionalString

CloudContainerEnvironment::OptionalString(string $name, string $defaultValue = ''): string

A string environment variable, base64 decoded, or the default when it is absent or empty after decoding. Throws when a present value fails to decode.

NameTypeDescription
$namestringThe environment variable name.
$defaultValuestringThe value returned when none is present.

Returns string The decoded value, or the default.

String

CloudContainerEnvironment::String(string $name): string

A string environment variable, base64 decoded and validated. Throws when the variable is missing, fails to decode, or is empty after decoding.

NameTypeDescription
$namestringThe environment variable name.

Returns string The decoded value.

CloudContainerEnvironmentPort

Builds CloudContainerEnvironmentPortData objects from decoded JSON.

FromJson

CloudContainerEnvironmentPort::FromJson(array $data): CloudContainerEnvironmentPortData

Build one port data object from a decoded JSON array. Throws when required fields are missing.

NameTypeDescription
$dataarrayThe decoded port fields.

Returns CloudContainerEnvironmentPortData The port data.

ListFromJson

CloudContainerEnvironmentPort::ListFromJson(array $jsonArray): array

Build a list of port data objects from a decoded JSON array of ports.

NameTypeDescription
$jsonArrayarrayAn array of port objects.

Returns array A list of CloudContainerEnvironmentPortData.

CloudContainerEnvironmentPortData

Immutable port configuration for a container environment. Fields and constructor, plus a JSON conversion.

Properties

PropertyTypeDescription
$port->portIdentifierstringThe port identifier (readonly).
$port->portNumberintThe port number, 1 to 65535 (readonly).
$port->adminToken?stringThe admin token, a 64-character hex string (readonly).
$port->sslCert?stringThe SSL certificate (readonly).
$port->sslKey?stringThe SSL key (readonly).
$port->sslCACert?stringThe SSL CA certificate (readonly).
Functions

__construct

new CloudContainerEnvironmentPortData(string $portIdentifier, int $portNumber, ?string $adminToken, ?string $sslCert, ?string $sslKey, ?string $sslCACert)

Create port configuration data.

Returns CloudContainerEnvironmentPortData

ToJson

CloudContainerEnvironmentPortData::ToJson(): string

The port data as a JSON string.

Returns string The JSON representation.

CloudContainerHeartbeat

Builds a heartbeat request object from JSON input.

Functions

FromJson

CloudContainerHeartbeat::FromJson(mixed $json): CloudContainerHeartbeatRequestData

Build a heartbeat request object from an array, object or JSON string, validating the counters and messages. Throws when the input is invalid or the service name or container ref is missing.

NameTypeDescription
$jsonmixedThe heartbeat data as an array, object or JSON string.

Returns CloudContainerHeartbeatRequestData The request data.

CloudContainerHeartbeatData

Immutable stored heartbeat data. Fields and constructor, plus JSON conversions.

Properties

PropertyTypeDescription
$heartbeat->idintThe heartbeat id (readonly).
$heartbeat->containerIdintThe container id (readonly).
$heartbeat->countersstringThe counter data as a JSON string (readonly).
$heartbeat->messagesstringThe message data as a JSON string (readonly).
$heartbeat->addedTimestampintWhen the heartbeat was added (readonly).

__construct

new CloudContainerHeartbeatData(int $id, int $containerId, string $counters, string $messages, int $addedTimestamp)

Create stored heartbeat data.

Returns CloudContainerHeartbeatData

FromJson

CloudContainerHeartbeatData::FromJson(string $json): CloudContainerHeartbeatData

Build stored heartbeat data from a JSON string, defaulting empty counters and messages to an empty array.

NameTypeDescription
$jsonstringThe JSON heartbeat object.

Returns CloudContainerHeartbeatData The heartbeat data.

ToJson

CloudContainerHeartbeatData::ToJson(): string

The heartbeat data as a JSON string.

Returns string The JSON representation.

CloudContainerHeartbeatDatabase

Store and read container heartbeats.

Add

CloudContainerHeartbeatDatabase::Add(string $serviceName, string $containerRef, array $counters, array $messages): int

Look up the container by service name and container ref, then store a heartbeat with its counters and messages. Throws when the container is not found.

NameTypeDescription
$serviceNamestringThe service name.
$containerRefstringThe container reference.
$countersarrayCounter entries, each with a name and value.
$messagesarrayA list of message strings.

Returns int The new heartbeat id.

CountByContainerId

CloudContainerHeartbeatDatabase::CountByContainerId(int $containerId): int

The number of heartbeats stored for a container.

NameTypeDescription
$containerIdintThe container id.

Returns int The heartbeat count.

fromRow

CloudContainerHeartbeatDatabase::fromRow(stdClass $row): CloudContainerHeartbeatData

Build a heartbeat data object from a database row.

NameTypeDescription
$rowstdClassThe database row.

Returns CloudContainerHeartbeatData The heartbeat data.

GetByContainerId

CloudContainerHeartbeatDatabase::GetByContainerId(int $containerId, int $limit = 100): array

The most recent heartbeats for a container, newest first.

NameTypeDescription
$containerIdintThe container id.
$limitintThe maximum number to return, 1 to 1000.

Returns array A list of CloudContainerHeartbeatData.

GetLatestByContainerId

CloudContainerHeartbeatDatabase::GetLatestByContainerId(int $containerId): ?CloudContainerHeartbeatData

The latest heartbeat for a container, or null when there is none.

NameTypeDescription
$containerIdintThe container id.

Returns ?CloudContainerHeartbeatData The latest heartbeat, or null.

CloudContainerHeartbeatRequestData

Immutable incoming heartbeat request data. Fields and constructor, plus a JSON conversion.

Properties

PropertyTypeDescription
$request->serviceNamestringThe service sending the heartbeat (readonly).
$request->containerRefstringThe container reference (readonly).
$request->countersarrayCounter entries, each with a name and value (readonly).
$request->messagesarrayA list of message strings (readonly).
Functions

__construct

new CloudContainerHeartbeatRequestData(string $serviceName, string $containerRef, array $counters, array $messages)

Create incoming heartbeat request data, validating the counters and messages.

Returns CloudContainerHeartbeatRequestData

ToJson

CloudContainerHeartbeatRequestData::ToJson(): string

The request data as a JSON string.

Returns string The JSON representation.

CloudContainerHeartbeatResponseData

Immutable heartbeat response data. Constructor only, plus a JSON conversion; no channel information is included.

Functions

__construct

new CloudContainerHeartbeatResponseData()

Create an empty heartbeat response.

Returns CloudContainerHeartbeatResponseData

ToJson

CloudContainerHeartbeatResponseData::ToJson(): string

The response as a JSON string.

Returns string The JSON representation.

CloudContainerStatusEnum

The container status constants used by CloudContainerData::$status.

Constants

ConstantValueDescription
CloudContainerStatusEnum::STARTING1The container is starting.
CloudContainerStatusEnum::RUNNING2The container is running.
CloudContainerStatusEnum::STOPPING3The container is stopping.
CloudContainerStatusEnum::STOPPED4The container is stopped.
CloudContainerStatusEnum::ERROR5The container is in error.

CloudDatabase

Start or stop a container through its vendor callback, guarded by the container's current status.

StartContainer

CloudDatabase::StartContainer(CloudContainerData $container): void

Start a container that is in STARTING status by calling its vendor start callback; returns without acting when it is not in STARTING status.

NameTypeDescription
$containerCloudContainerDataThe container to start.

Returns void

StopContainer

CloudDatabase::StopContainer(CloudContainerData $container): void

Stop a container that is in STOPPING status by calling its vendor stop callback; returns without acting when it is not in STOPPING status.

NameTypeDescription
$containerCloudContainerDataThe container to stop.

Returns void

CloudQueue

Process a queued container start or stop by container id.

ProcessStartContainer

CloudQueue::ProcessStartContainer(int $containerId): void

Load the container by id and, when it is in STARTING status, call its vendor start callback.

NameTypeDescription
$containerIdintThe container id.

Returns void

ProcessStopContainer

CloudQueue::ProcessStopContainer(int $containerId): void

Load the container by id and, when it is in STOPPING status, call its vendor stop callback.

NameTypeDescription
$containerIdintThe container id.

Returns void

CloudServerData

Immutable data for a server that hosts containers. Fields and constructor only.

Properties

PropertyTypeDescription
$server->idintThe server id (readonly).
$server->vendorIdentifierstringThe vendor identifier (readonly).
$server->identifierstringThe server identifier (readonly).
$server->namestringThe server name (readonly).
$server->ipAddressstringThe server IP address (readonly).
$server->addedTimestampintWhen the server was added (readonly).
$server->managementPort?intThe management port (readonly).
$server->managementToken?stringThe management token (readonly).
Functions

__construct

new CloudServerData(int $id, string $vendorIdentifier, string $identifier, string $name, string $ipAddress, int $addedTimestamp, ?int $managementPort = null, ?string $managementToken = null)

Create server data from its fields.

Returns CloudServerData

CloudServerDatabase

Read servers from the database by id or identifier.

fromRow

CloudServerDatabase::fromRow(stdClass $row): CloudServerData

Build a server data object from a database row.

NameTypeDescription
$rowstdClassThe database row.

Returns CloudServerData The server data.

GetById

CloudServerDatabase::GetById(int $serverId): CloudServerData

The server with the given id. Throws when there is no matching row.

NameTypeDescription
$serverIdintThe server id.

Returns CloudServerData The server data.

GetByIdentifier

CloudServerDatabase::GetByIdentifier(string $serverIdentifier): CloudServerData

The server with the given identifier, matched in lowercase. Throws when there is no matching row.

NameTypeDescription
$serverIdentifierstringThe server identifier.

Returns CloudServerData The server data.

CloudServiceConfig

Register cloud services and the container admin sections that render their service-specific information. Services are keyed by a lowercase identifier.

Properties

PropertyTypeDescription
CloudServiceConfig::$servicesarrayThe registered service objects.
CloudServiceConfig::$containerAdminSectionsarrayThe registered admin section callbacks, keyed by service identifier.

AddContainerAdminSection

CloudServiceConfig::AddContainerAdminSection(string $serviceIdentifier, callable $containerAdminSectionCallback): void

Register a callback that renders service-specific container information in the admin.

NameTypeDescription
$serviceIdentifierstringThe service identifier; lowercased before use.
$containerAdminSectionCallbackcallableCallback that receives the container id and renders the UI.

Returns void

AddService

CloudServiceConfig::AddService(string $serviceIdentifier, string $description = ''): void

Register a service by identifier. Throws when the service is already registered.

NameTypeDescription
$serviceIdentifierstringThe service identifier; lowercased before use.
$descriptionstringAn optional description of the service.

Returns void

GetContainerAdminSection

CloudServiceConfig::GetContainerAdminSection(string $serviceIdentifier): ?callable

The admin section callback for a service, or null when none is registered.

NameTypeDescription
$serviceIdentifierstringThe service identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetServiceIdentifiers

CloudServiceConfig::GetServiceIdentifiers(): array

The identifiers of every registered service.

Returns array A list of service identifiers.

GetServices

CloudServiceConfig::GetServices(): array

Every registered service object.

Returns array A list of service objects.

CloudStartQueueDatabase

Lock and process containers awaiting start. Used as the start queue's lock-next and process callbacks.

Functions

LockNext

CloudStartQueueDatabase::LockNext(int $limit): array

Lock and return the ids of up to a number of containers in STARTING status, using SELECT ... FOR UPDATE SKIP LOCKED. Called within a transaction.

NameTypeDescription
$limitintThe maximum number of rows to lock and return.

Returns array A list of container ids.

Process

CloudStartQueueDatabase::Process(int $containerId): void

Load the container by id and, when it is in STARTING status, call its vendor start callback.

NameTypeDescription
$containerIdintThe container id.

Returns void

CloudStopQueueDatabase

Lock and process containers awaiting stop. Used as the stop queue's lock-next and process callbacks.

Functions

LockNext

CloudStopQueueDatabase::LockNext(int $limit): array

Lock and return the ids of up to a number of containers in STOPPING status, using SELECT ... FOR UPDATE SKIP LOCKED. Called within a transaction.

NameTypeDescription
$limitintThe maximum number of rows to lock and return.

Returns array A list of container ids.

Process

CloudStopQueueDatabase::Process(int $containerId): void

Load the container by id and, when it is in STOPPING status, call its vendor stop callback.

NameTypeDescription
$containerIdintThe container id.

Returns void

CloudVendorConfig

Register cloud vendors and their start, stop and status callbacks, and read them back. Vendors are keyed by a lowercase identifier.

Properties

PropertyTypeDescription
CloudVendorConfig::$vendorsarrayThe registered vendor objects.
CloudVendorConfig::$containerProcessorsarrayThe registered container processor callbacks, keyed by vendor identifier.
CloudVendorConfig::$containerAdminSectionsarrayThe registered admin section callbacks, keyed by vendor identifier.
CloudVendorConfig::$containerStatusPanelsarrayThe registered status panel callbacks, keyed by vendor identifier.

AddContainerAdminSection

CloudVendorConfig::AddContainerAdminSection(string $vendorIdentifier, callable $containerAdminSectionCallback): void

Register a callback that renders vendor-specific container information in the admin.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before use.
$containerAdminSectionCallbackcallableCallback that receives the container id and renders the UI.

Returns void

AddContainerProcessor

CloudVendorConfig::AddContainerProcessor(string $vendorIdentifier, callable $processorCallback): void

Register a processor callback for a vendor. Deprecated: use AddVendor with start and stop container callbacks instead.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before use.
$processorCallbackcallableCallback that receives a container id and processes it.

Returns void

AddContainerStatusPanel

CloudVendorConfig::AddContainerStatusPanel(string $vendorIdentifier, callable $containerStatusPanelCallback): void

Register a callback that renders a vendor-specific container status panel.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before use.
$containerStatusPanelCallbackcallableCallback that receives a CloudContainerData and renders the status panel.

Returns void

AddVendor

CloudVendorConfig::AddVendor(string $vendorIdentifier, string $vendorName, ?callable $startContainerCallback = null, ?callable $stopContainerCallback = null, ?callable $startServerCallback = null, ?callable $stopServerCallback = null, ?callable $getContainerStatusCallback = null): void

Register a vendor and its start, stop and status callbacks. Throws when the vendor is already registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before use.
$vendorNamestringThe human-readable vendor name.
$startContainerCallback?callableCallback to start a container, receiving the container object.
$stopContainerCallback?callableCallback to stop a container, receiving the container object.
$startServerCallback?callableCallback to start a server, receiving the server id.
$stopServerCallback?callableCallback to stop a server, receiving the server id.
$getContainerStatusCallback?callableCallback to read a container's status.

Returns void

GetContainerAdminSection

CloudVendorConfig::GetContainerAdminSection(string $vendorIdentifier): ?callable

The admin section callback for a vendor, or null when none is registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetContainerProcessor

CloudVendorConfig::GetContainerProcessor(string $vendorIdentifier): ?callable

The processor callback for a vendor, or null when none is registered. Deprecated: use GetStartContainerCallback and GetStopContainerCallback instead.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetContainerStatusCallback

CloudVendorConfig::GetContainerStatusCallback(string $vendorIdentifier): ?callable

The status callback for a vendor, or null when none is registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetContainerStatusPanel

CloudVendorConfig::GetContainerStatusPanel(string $vendorIdentifier): ?callable

The status panel callback for a vendor, or null when none is registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetStartContainerCallback

CloudVendorConfig::GetStartContainerCallback(string $vendorIdentifier): ?callable

The start container callback for a vendor, or null when none is registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetStartServerCallback

CloudVendorConfig::GetStartServerCallback(string $vendorIdentifier): ?callable

The start server callback for a vendor, or null when none is registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetStopContainerCallback

CloudVendorConfig::GetStopContainerCallback(string $vendorIdentifier): ?callable

The stop container callback for a vendor, or null when none is registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetStopServerCallback

CloudVendorConfig::GetStopServerCallback(string $vendorIdentifier): ?callable

The stop server callback for a vendor, or null when none is registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?callable The callback, or null.

GetVendorIdentifiers

CloudVendorConfig::GetVendorIdentifiers(): array

The identifiers of every registered vendor.

Returns array A list of vendor identifiers.

GetVendorName

CloudVendorConfig::GetVendorName(string $vendorIdentifier): ?string

The human-readable name for a vendor, or null when the vendor is not registered.

NameTypeDescription
$vendorIdentifierstringThe vendor identifier; lowercased before lookup.

Returns ?string The vendor name, or null.

GetVendors

CloudVendorConfig::GetVendors(): array

Every registered vendor object.

Returns array A list of vendor objects.