PHPackages                             marcoconsiglio/phprimes-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. marcoconsiglio/phprimes-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marcoconsiglio/phprimes-generator
=================================

A PHP primes number generator originally created by Pol Dellaiera.

v2.0.0(4mo ago)04MITPHP

Since Jan 5Pushed 4mo agoCompare

[ Source](https://github.com/MarcoConsiglio/phprimes-generator)[ Packagist](https://packagist.org/packages/marcoconsiglio/phprimes-generator)[ RSS](/packages/marcoconsiglio-phprimes-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

[![GitHub License](https://camo.githubusercontent.com/562f09df894aa5c53f149885e28a52e73f3d73f8b891360ffd460f134d5f3f1b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d6172636f436f6e7369676c696f2f70687072696d65732d67656e657261746f72)](https://camo.githubusercontent.com/562f09df894aa5c53f149885e28a52e73f3d73f8b891360ffd460f134d5f3f1b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d6172636f436f6e7369676c696f2f70687072696d65732d67656e657261746f72)[![GitHub Release](https://camo.githubusercontent.com/54b7e4334ecffb5a39127d744028f3e321e44983adc727db66ea16007d79ed0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4d6172636f436f6e7369676c696f2f70687072696d65732d67656e657261746f72)](https://camo.githubusercontent.com/54b7e4334ecffb5a39127d744028f3e321e44983adc727db66ea16007d79ed0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4d6172636f436f6e7369676c696f2f70687072696d65732d67656e657261746f72)[![Static Badge](https://camo.githubusercontent.com/d4328ab5c417ed75b6391600f046ac11a6644b8d2f333cb5bc0444e84fbf2edd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f63757272656e745f76657273696f6e2d76322e302e302d7768697465)](https://camo.githubusercontent.com/d4328ab5c417ed75b6391600f046ac11a6644b8d2f333cb5bc0444e84fbf2edd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f63757272656e745f76657273696f6e2d76322e302e302d7768697465)
[![Static Badge](https://camo.githubusercontent.com/42eb7ff0fc4a4f2823d36de6d70f5f0b656d1a3e5abf9fd9b6b4adb3bafbb111/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f32362532352d7267622831363625324325323033382532432532303531293f6c6162656c3d4c696e65253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)](https://camo.githubusercontent.com/42eb7ff0fc4a4f2823d36de6d70f5f0b656d1a3e5abf9fd9b6b4adb3bafbb111/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f32362532352d7267622831363625324325323033382532432532303531293f6c6162656c3d4c696e65253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)[![Static Badge](https://camo.githubusercontent.com/a00db2df5a3e1d26458ed59482ae1a53bd3b96a219698ac9ccc85212abf3cb86/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f32392532352d7267622831363625324325323033382532432532303531293f6c6162656c3d4272616e6368253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)](https://camo.githubusercontent.com/a00db2df5a3e1d26458ed59482ae1a53bd3b96a219698ac9ccc85212abf3cb86/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f32392532352d7267622831363625324325323033382532432532303531293f6c6162656c3d4272616e6368253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)[![Static Badge](https://camo.githubusercontent.com/0edfe7d5c4e23174ddc83e576952046a2c7e0c8a8a2537f8d7a78da39e18256f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f32362532352d7267622831363625324325323033382532432532303531293f6c6162656c3d50617468253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)](https://camo.githubusercontent.com/0edfe7d5c4e23174ddc83e576952046a2c7e0c8a8a2537f8d7a78da39e18256f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f32362532352d7267622831363625324325323033382532432532303531293f6c6162656c3d50617468253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)

PHPrimes Generator
==================

[](#phprimes-generator)

A PHP primes number generator originally created by [*Pol Dellaiera*](https://github.com/drupol) in its [drupol/primes-bench](https://github.com/drupol/primes-bench) repo.

Installation
============

[](#installation)

```
composer require marcoconsiglio/phprimes-generator

```

Usage
=====

[](#usage)

`OptimusPrime` is the library endpoint to use the [`Prime3` class](https://github.com/drupol/primes-bench/blob/master/src/Primes3.php) which is the best performing prime number generator written by *Pol Dellaiera*.

Keep in mind that:

- the generator in question continues forever, so it is highly recommended to set a limit (by default it is the first 500 prime numbers);
- random access is not possible, like in `$primes[$i]`;
- if you rewind the iterator, it start over again.

```
use MarcoConsiglio\PHPrimesGenerator\OptimusPrime;

// Generate the first 5 prime numbers.
$primes = new OptimusPrime(5)->generate();
// For older PHP versions use this
// $primes = (new OptimusPrime(5))->generate();
foreach($primes as $number) {
    echo $number.PHP_EOL;
}
```

```
2
3
5
7
11

```

Integer safe iterator
---------------------

[](#integer-safe-iterator)

The `OptimusPrime` class uses an integer safe iterator which throws exception `MaximumIntegerIteratorValueReached` when PHP\_INT\_MAX + 1 value is reached.

```
use MarcoConsiglio\PHPrimesGenerator\OptimusPrime;

try {
    $primes = new OptimusPrime(PHP_MAX_INT)->generate();
    foreach($primes as $number) {
        echo $number.PHP_EOL;
    }
} catch (MaximumIntegerIteratorValueReached $e) {
    echo $e->getMessage();
}
```

Generate to file
----------------

[](#generate-to-file)

Do you rapidly need primes numbers on a text file? Uncomment the test method `OptimusPrimeTest::test_record_primes_numbers_to_file()`, set a `$limit` of your preference and launch the same test method with:

```
vendor/bin/phpunit --filter=test_record_primes_numbers_to_file
```

You will find your file in [`prime_numbers.txt`](prime_numbers.txt);

API documentation
=================

[](#api-documentation)

You can find API documentation in [`docs/html`](docs/html/index.html).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance77

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

125d ago

Major Versions

v1.1.0 → v2.0.02026-01-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/5fb36102dfc597a74e864afc65952e328f158bff88f21ad993c1d79c51c80133?d=identicon)[MarcoConsiglio](/maintainers/MarcoConsiglio)

---

Top Contributors

[![MarcoConsiglio](https://avatars.githubusercontent.com/u/39809954?v=4)](https://github.com/MarcoConsiglio "MarcoConsiglio (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marcoconsiglio-phprimes-generator/health.svg)

```
[![Health](https://phpackages.com/badges/marcoconsiglio-phprimes-generator/health.svg)](https://phpackages.com/packages/marcoconsiglio-phprimes-generator)
```

###  Alternatives

[dm/ajaxcom

Controls Ajax from PHP

1816.4k](/packages/dm-ajaxcom)[slack/hack-json-schema

Hack JSON Schema generator

302.4k](/packages/slack-hack-json-schema)[proai/lumen-annotations

Route and event binding annotations for Laravel Lumen

1012.4k](/packages/proai-lumen-annotations)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
