Download the PHP package utopia-php/usage without Composer

On this page you can find all versions of the php package utopia-php/usage. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package usage

Utopia Usage

Total Downloads Discord

Utopia framework usage library is a simple and lite library for managing application usage statistics. This library is aiming to be as simple and easy to learn and use. This library is maintained by the Appwrite team.

Although this library is part of the Utopia Framework project it is dependency free and can be used as standalone with any other PHP project or framework.

Features

Getting Started

Install using composer:

Using ClickHouse Adapter

Using Database Adapter

Multi-tenancy

Usage is stateless: every query/mutation takes the tenant as its first argument, and addBatch carries a tenant on each metric row (so one batch can span tenants). This makes a single Usage instance safe to share across tenants and coroutines.

Callers that only ever touch one tenant can bind it once with the Tenant decorator, which forwards to Usage with the tenant pre-filled (and stamps it onto every addBatch row):

Metric Types

Events (Additive)

Events are request-level metrics like bandwidth, executions, API calls. They are summed when aggregated.

Event-specific columns (see Metric::EVENT_COLUMNS): path, method, status, service, resource, resourceId, resourceInternalId, teamId, teamInternalId, country, region, hostname, osCode, osName, osVersion, clientType, clientCode, clientName, clientVersion, clientEngine, clientEngineVersion, deviceName, deviceBrand, deviceModel.

Strict tag keys

All keys passed in the tags array must map to a known event or gauge column (see Metric::EVENT_COLUMNS and Metric::GAUGE_COLUMNS). Unknown keys throw at write time — there is no JSON catch-all. To add a new dimension, widen the schema and bump the library version.

Gauges (Point-in-Time)

Gauges are resource snapshots like storage size, user count, file count. Last-write-wins semantics.

Gauge-specific columns (see Metric::GAUGE_COLUMNS): teamId, teamInternalId, resourceId, resourceInternalId.

Flushing

The accumulator exposes raw signals — count() (buffered entries) and elapsedSeconds() (seconds since last flush) — and leaves the flush policy to the caller.

Batch Writes

Canonical Samples

Billable inputs that must survive request retries use the separate immutable sample ledger. A sample's identity is derived from its environment, region, project and database internal IDs, member, generation, sequence and metric. Retrying the same identity and payload is safe. Reusing an identity with a different interval, value or event version is returned as a conflict. The event ID is SHA-256 over those identity fields in the documented order, each encoded as its decimal byte length, :, then its UTF-8 value. The payload hash uses the same encoding over event ID, UTC millisecond interval bounds, value and event version.

Each supplied sample row receives an adapter-owned random ingestion ID before its request is sent. getSampleWatermark() performs one bounded ClickHouse snapshot read and captures each visible ingestion ID bound to its canonical ID and payload hash for that stream and range. findSamples() admits only those exact entry fingerprints, so later inserts or changed rows cannot cross the boundary even when their server timestamps would be identical. A transport retry of the same request retains its fingerprint and is counted once; a new logical retry gets a new ingestion ID and is included only when visible to the watermark query.

Both the watermark evidence and findSamples() result are explicitly bounded. A result is complete only when neither bound is truncated and there are no conflicts, sequence gaps or interval-boundary discontinuities. Conflicting physical rows are never combined into a synthetic sample. The sample ledger does not make HTTP delivery or a producer's local spool durable; callers must retain a sample until the write is acknowledged and retry the identical payload.

Querying Metrics

Find with Query Objects

Totals

Time Series

Billing Queries (Daily MV)

The daily materialized view pre-aggregates events by metric + tenant + day for fast billing:

Purge

Architecture

ClickHouse Tables

Table Engine Purpose
{ns}_usage_events MergeTree Raw request events with full metadata
{ns}_usage_gauges MergeTree Resource snapshot gauges
{ns}_usage_events_daily SummingMergeTree Pre-aggregated daily event totals
{ns}_usage_events_daily_mv Materialized View Auto-populates daily table on insert
{ns}_usage_samples MergeTree Immutable canonical samples with retry/conflict evidence

Events Table Schema

Column Type Description
id String UUID
metric String Metric name (e.g. bandwidth, requests)
value Int64 Metric value
time DateTime64(3) Event timestamp
path Nullable(String) API endpoint path
method Nullable(String) HTTP method
status Nullable(String) HTTP status code
service LowCardinality(Nullable(String)) API service (storage, databases, …)
resource LowCardinality(Nullable(String)) Resource type (bucket, file, …)
resourceId Nullable(String) External resource id
resourceInternalId Nullable(String) Internal resource sequence
teamId Nullable(String) External team id
teamInternalId Nullable(String) Internal team sequence
country LowCardinality(Nullable(String)) ISO country code (lowercased)
region LowCardinality(Nullable(String)) Region code (lowercased)
hostname Nullable(String) Caller origin host
osCode, osName LowCardinality(Nullable(String)) Parsed OS short code / name
osVersion Nullable(String) Parsed OS version
clientType, clientCode, clientName, clientEngine LowCardinality(Nullable(String)) Parsed client identity
clientVersion, clientEngineVersion Nullable(String) Parsed client versions
deviceName, deviceBrand LowCardinality(Nullable(String)) Parsed device identity
deviceModel Nullable(String) Parsed device model
tenant Nullable(String) Tenant ID (shared tables)

Gauges Table Schema

Column Type Description
id String UUID
metric String Metric name
value Int64 Current value
time DateTime64(3) Snapshot timestamp
teamId Nullable(String) External team id
teamInternalId Nullable(String) Internal team sequence
resourceId Nullable(String) External resource id
resourceInternalId Nullable(String) Internal resource sequence
tenant Nullable(String) Tenant ID (shared tables)

Daily Table Schema

Column Type Description
metric String Metric name
value Int64 Aggregated daily sum
time DateTime64(3) Day start timestamp
resource LowCardinality(Nullable(String)) Resource type
resourceId Nullable(String) External resource id
resourceInternalId Nullable(String) Internal resource sequence
teamId Nullable(String) External team id
teamInternalId Nullable(String) Internal team sequence
tenant Nullable(String) Tenant ID (shared tables)

Creating Custom Adapters

Extend Utopia\Usage\Adapter and implement:

All configuration — namespace, database, shared-tables mode, async inserts, query logging — is set once via the adapter constructor (see "Using ClickHouse Adapter" above). Adapters hold no per-request state; the tenant is passed explicitly on every call, so one instance is safe to share across tenants and coroutines.

System Requirements

Utopia Framework requires PHP 8.4 or later. We recommend using the latest PHP version whenever possible.

Copyright and license

The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php


All versions of usage with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
psr/http-client Version ^1.0
utopia-php/client Version ^0.5
utopia-php/database Version ^7.0.0
utopia-php/query Version 0.6.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package utopia-php/usage contains the following files

Loading the files please wait ...