Skip to content
/ stream-sampler Public template

Example PHP Command-line Application based on Symlex Core


Notifications You must be signed in to change notification settings


Folders and files

Last commit message
Last commit date

Latest commit



29 Commits

Repository files navigation

Example CLI app based on Symlex Core

License: MIT Build Status Documentation Community Chat

This application is compatible with PHP 7.1+ with the curl extension enabled.

Clone this repository to a local directory and run composer:

git clone
cd stream-sampler
composer update

Alternatively you can run composer to create a new project from the latest stable release and fetch external dependencies:

composer create-project symlex/stream-sampler my-stream-sampler

Composer will ask for config values to generate app/config/parameters.yml for you.

YAML files located in app/config configure the app based on parameters and services. The main config file is app/config/console.yml.

What does a stream sampler do?

It randomly returns a representative sample of k items from a stream of values with unknown and possibly very large length. The implementation relies on Algorithm R, which has a complexity of O(N). See


app/console sample [options]

  -i, --input[=INPUT]   Input source (stdin,, internal) [default: "stdin"]
  -s, --size[=SIZE]     Sample size (1 - 2000) [default: 5]
  -V, --version         Display the application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output

Note: If you're using or the internal random character source, input data size will be 10 times the sample size. The maximum sample size is 2000.


# app/console sample -i internal -s 10

# app/console sample -i -s 8

# app/console sample < LICENSE

# echo 'Pe7emsXm0EHfwAVx' | app/console sample


Stream Sampler comes with a pre-configured PHPUnit environment that automatically executes tests found in src/:

PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

.......                                         7 / 7 (100%)

Time: 431 ms, Memory: 8.00MB

OK (7 tests, 16892 assertions)

See also: (self-initializing database fixtures and dependency injection for unit tests)

Similar work