Download the PHP package antikirra/probability without Composer

On this page you can find all versions of the php package antikirra/probability. 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 probability

Make your code work spontaneously ๐Ÿ™ƒ

Packagist Dependency Version Packagist Version

A lightweight PHP library for probabilistic code execution and deterministic feature distribution. Perfect for A/B testing, gradual feature rollouts, performance sampling, and controlled chaos engineering.

Quick Start

Install

Requires PHP 8.2 or newer. Zero runtime dependencies.

๐Ÿš€ Key Features

๐Ÿ’ก Use Cases

๐Ÿ”ฌ How It Works

The library uses two strategies for probability calculation:

1. Pure Random (No Key)

When called without a key, uses PHP's mt_rand() for true randomness:

2. Deterministic (With Key)

When provided with a key, uses CRC32 hashing for consistent results:

Technical Details:

The deterministic approach ensures:

๐Ÿ“– API Reference

Parameters

Returns

Examples

๐ŸŽฏ Best Practices

1. Use Meaningful Keys

2. Separate Features

3. Consider Scale

๐Ÿ“Š When to Use: Random vs Deterministic

Scenario Use Random (no key) Use Deterministic (with key)
Performance sampling โœ… Sample random requests โŒ Would sample same requests
Logging/Debugging โœ… Random sampling โŒ Not needed for logs
A/B Testing โŒ Inconsistent UX โœ… User sees same variant
Feature Rollout โŒ Unpredictable access โœ… Stable feature access
Chaos Engineering โœ… Random failures โš ๏ธ Depends on use case
Load Testing โœ… Random distribution โŒ Predictable patterns
Canary Deployment โŒ Unstable routing โœ… Consistent routing
User Segmentation โŒ Segments change โœ… Stable segments

๐Ÿ’ป Real-World Examples

Laravel: Feature Flag Middleware

Symfony: Performance Monitoring

WordPress: A/B Testing

API Rate Limiting by Tier

๐Ÿงช Testing

The library includes a comprehensive Pest test suite covering edge cases, statistical correctness, and deterministic behavior.

Test coverage includes:

โšก Performance

Benchmarks on PHP 8.4 (Apple M4 Pro):

Operation Time per call Ops/sec
Random (no key) ~0.12 ฮผs ~8.4M
Deterministic (with key) ~0.15 ฮผs ~6.7M

Memory usage: 0 bytes (no allocations)

The library is optimized for high-throughput scenarios:

Run php benchmark.php to test performance on your hardware.

โ“ FAQ / Troubleshooting

Why do I get different results in different environments?

Q: Same key returns different results on different servers.

A: This is expected! CRC32 implementation is consistent, but you might be using different keys. Ensure you're using the exact same key string across environments.

Why is my A/B test showing 52% instead of 50%?

Q: I'm using probability(0.5, $userId) but getting uneven distribution.

A: With small sample sizes, variance is normal. The distribution converges to 50% with larger samples (law of large numbers). For 100 users, expect 45-55%. For 10,000 users, expect 49-51%.

Can I use this for cryptographic purposes?

Q: Is this secure for generating random tokens?

A: No! This library is NOT cryptographically secure. CRC32 is predictable and mt_rand() is not suitable for security. Use random_bytes() or random_int() for security purposes.

How do I gradually increase rollout percentage?

Q: I want to go from 10% to 50% to 100%.

A: Just change the probability value in your code/config. Users in the 0-10% hash range stay enabled, users in 10-50% get added, etc.

What about hash collisions?

Q: Can different keys produce the same result?

A: Yes, CRC32 has only 2ยณยฒ (~4.3 billion) possible values. With many keys, collisions are possible but rare for typical use cases. For most applications this is acceptable. If you need collision-resistant hashing, fork and replace CRC32 with MD5 or SHA256.

Why not use a database for feature flags?

Q: Isn't a feature flag service better?

A: Depends on your needs:

This library excels at simplicity and performance, not flexibility.


All versions of probability with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
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 antikirra/probability contains the following files

Loading the files please wait ...