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, this library uses in-memory caching to track events and spot unusual patterns before it is too late.

Features

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:

Five standard deviations from the mean is a definite anomaly: there's only a ~0.000057% chance that a data point this extreme occurs by random chance under the null hypothesis.

Available Cache Adapters

The library supports multiple caching backends through a simple adapter interface. An example using regular Memcached:

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:

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.

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.

License

This library is dual-licensed under the GNU General Public License v2.0 or later and the Apache License 2.0. You may choose either license to govern your use of this software.

When using this library, you must comply with the terms of at least one of these licenses.

All contributions to this project have been reviewed and confirmed by the respective authors as dual-licensed. If you believe your code was included without proper attribution or license representation, please contact us and we'll address it immediately.


All versions of sliding-window-counter with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
sanmai/duoclock Version ^0.1.0
sanmai/pipeline Version ^6.22 || ^7.0
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 ....