Download the PHP package sanmai/sliding-window-counter without Composer

On this page you can find all versions of the php package sanmai/sliding-window-counter. 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 sliding-window-counter

Sliding Window Counter 📊⏱️

Latest Stable Version License

Short-lived cache-backed time series with anomaly detection

A lightweight, efficient PHP library for tracking time-based events and detecting anomalies without the overhead of databases or logs.

Table of Contents

Installation

What's this all about?

Ever needed to track how many times something happens over time and spot when those numbers get weird? That's what this library does, and it does it efficiently.

Real-world example: Imagine you want to detect when suspicious messages from specific IP ranges suddenly spike. Instead of digging through logs or querying databases (slow and resource-hungry), this library uses in-memory caching to track events and spot unusual patterns.

Features

Lightweight - Uses your existing cache infrastructure
Fast - No database queries or log parsing
Statistical anomaly detection - Based on standard deviations
Flexible time windows - Configure to your needs
Production-ready - Originally developed at Automattic for Tumblr

How it works (the simple version)

  1. Divide time into buckets - We slice time into equal chunks (like 5-minute windows or hourly buckets)
  2. Count events in cache - Each event increments a counter in the appropriate time bucket
  3. Create time series on demand - When needed, we assemble these buckets into a continuous series
  4. Apply statistical analysis - We calculate mean, standard deviation, and detect outliers

The library handles all the tricky parts like:

Quick Start

Setting up a counter

Tracking events

Detecting unusual activity

Getting more stats

Adjusting Sensitivity

You can control how sensitive the anomaly detection is by specifying the number of standard deviations that define "normal":

A quick stats refresher:

Choosing the Right Sensitivity

Sensitivity Best For False Positive Rate
1 Early warning systems, where cost of missing an event is high ~32%
2 General purpose anomaly detection ~5%
3 Critical systems where false alarms are costly ~0.3%
5 Mission-critical infrastructure, fraud detection ~0.00006%

Available Cache Adapters

The library supports multiple caching backends through a simple adapter interface:

Creating Your Own Adapter

Need to use a different cache system? Implementing a custom adapter is straightforward:

Technical Details (for the curious)

The library uses an elegant sliding window approach to time series data. Here's how it works under the hood:

Key Concepts

When calculating values for logical frames that don't perfectly align with material frames, we perform weighted extrapolation to ensure smooth transitions in the time series.

Visual Explanation

Consider these two scenarios:

  1. Perfectly aligned frames: When the query time aligns with cache bucket boundaries, we can use the raw values directly.

  1. Misaligned frames: When the query time doesn't align with cache boundaries, we extrapolate values based on overlapping portions.

For a more detailed explanation of the internal workings, check out this Cloudflare blog post which explains a similar approach.

Performance Considerations

Contributing

Contributions are welcome! Here are some ways you can contribute:

Please ensure your code follows the existing style and includes appropriate tests.

License

This library is licensed under the GNU General Public License v2.0. See the LICENSE file for details.


All versions of sliding-window-counter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
sanmai/pipeline Version ^6.11
tumblr/chorus-timekeeper Version ^0.1
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 sanmai/sliding-window-counter contains the following files

Loading the files please wait ....