PHPackages                             php-science/pagerank - 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. php-science/pagerank

ActiveLibrary

php-science/pagerank
====================

OOP Pagerank implementation with strict type.

1.0.1(5y ago)71571[1 issues](https://github.com/PHP-Science/Pagerank/issues)MITPHPPHP 7.4.\*

Since Sep 19Pushed 5y ago2 watchersCompare

[ Source](https://github.com/PHP-Science/Pagerank)[ Packagist](https://packagist.org/packages/php-science/pagerank)[ RSS](/packages/php-science-pagerank/feed)WikiDiscussions master Synced 5d ago

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

PageRank
=========

[](#pagerank)

 [ ![](https://github.com/php-science/pagerank/workflows/tests/badge.svg) ](https://github.com/PHP-Science/PageRank/actions) [ ![](https://camo.githubusercontent.com/3ab859eb8a5820a63108bdff449213bbe26225871704c506307037737da55f90/68747470733a2f2f636f6465636f762e696f2f67682f5048502d536369656e63652f5061676552616e6b2f6272616e63682f6d61737465722f67726170682f62616467652e737667) ](https://codecov.io/gh/PHP-Science/PageRank) [ ![](https://camo.githubusercontent.com/8bf3929fd205a11e6cb793a3e75e5f8b72a8802a93e502116013f6a082aec175/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f34386131306462323634366164346365383930632f6d61696e7461696e6162696c697479) ](https://codeclimate.com/github/PHP-Science/PageRank/maintainability) [ ![](https://camo.githubusercontent.com/17f7d306066afc76a2a3706804a0f28edae1a27229e6844a2782303b6e2e6a00/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5048502d536369656e63652f5061676552616e6b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572) ](https://scrutinizer-ci.com/g/PHP-Science/PageRank) [ ![](https://camo.githubusercontent.com/090d75c611b0f86a8d185a0800e657cc9edc23f104a327e220e113734be728dc/68747470733a2f2f706f7365722e707567782e6f72672f7068702d736369656e63652f7061676572616e6b2f762f737461626c652e737667) ](https://packagist.org/packages/php-science/pagerank)

This source code is an OOP implementation of the PageRank algorithm.

About
-----

[](#about)

This implementation is based on Larry Page's PageRank algorithm. It weights the connections between the nodes in a graph. In theory, the nodes can be websites, words, people, etc. As the number of the nodes are increasing the algorithm is becoming slower. To scale the size and handle millions of nodes, the accuracy of the calculation can be limited, and the long-running calculation can be scheduled in batches using the Strategy OOP pattern in the implementation.

Workflow
--------

[](#workflow)

- It calculates the initial ranking values. At the first iteration, all the nodes have the same rank.
- Iterates the nodes using the power method/iteration technique over and over again until it reaches the maximum iteration number.
- However, the iteration stops when the ranks are accurate enough even if the max iteration didn't reach its limit.
- The accuracy measured by the float epsilon constant.
- At the end, the algorithm normalizes the ranks between 0 and 1 and then scale them between 1 and 10. The scaling range is configurable.
- Getting, setting, updating the nodes from the resource is a responsibility of the NodeDataSourceStrategyInterface.
- The package provides a simple implementation of the NodeDataSourceStrategyInterface that only keeps the nodes in the memory. Another way of implementing the NodeDataSourceStrategyInterface could be a simple class that uses an ORM to handle the node collection.

Install
-------

[](#install)

```
composer require php-science/pagerank

```

Example
-------

[](#example)

```
$dataSource = $this->getYourDataSource();

$nodeBuilder = new NodeBuilder();
$nodeCollectionBuilder = new NodeCollectionBuilder();
$strategy = new MemorySourceStrategy(
    $nodeBuilder,
    $nodeCollectionBuilder,
    $dataSource
);

$rankComparator = new RankComparator();
$ranking = new Ranking(
    $rankComparator,
    $strategy
);

$normalizer = new Normalizer();

$pageRankAlgorithm = new PageRankAlgorithm(
    $ranking,
    $strategy,
    $normalizer
);

$maxIteration = 100;
$nodeCollection = $pageRankAlgorithm->run($maxIteration);

var_dump($nodeCollection->getNodes());
```

Functional Sample
-----------------

[](#functional-sample)

- test: [Functional test case](https://github.com/PHP-Science/PageRank/blob/master/tests/functional/Service/PageRankAlgorithmTest.php)
- running the test: `composer test`

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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 ~0 days

Total

2

Last Release

2064d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eacbba58f033fd357be083354cbee58abca8dab85d7c6ee5c22dbf71bf035a67?d=identicon)[DavidBelicza](/maintainers/DavidBelicza)

---

Top Contributors

[![DavidBelicza](https://avatars.githubusercontent.com/u/5840286?v=4)](https://github.com/DavidBelicza "DavidBelicza (26 commits)")

---

Tags

pagerankpagerank-algorithmphpautomaticstrictphp8summarizationsciencePagerank

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/php-science-pagerank/health.svg)

```
[![Health](https://phpackages.com/badges/php-science-pagerank/health.svg)](https://phpackages.com/packages/php-science-pagerank)
```

###  Alternatives

[php-science/textrank

TextRank (automatic text summarization) for PHP.

2461.7M3](/packages/php-science-textrank)[adhocore/cli

Command line interface library for PHP

3501.2M50](/packages/adhocore-cli)[abcaeffchen/sephpa

Generates SEPA files for credit transfers (pain.001.001.03, pain.001.002.03, pain.001.003.03, pain.001.001.09) and direct debit (pain.008.001.02, pain.008.002.02, pain.008.003.02, pain.008.001.08)

711.7M](/packages/abcaeffchen-sephpa)[butschster/cron-expression-generator

Cron expression generator

511.4M2](/packages/butschster-cron-expression-generator)[abcaeffchen/sepa-utilities

SepaUtilities provides useful methods for validating and sanitizing inputs used in SEPA files supporting PHP &gt;= 8.1.

312.0M2](/packages/abcaeffchen-sepa-utilities)[druidfi/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

35489.8k6](/packages/druidfi-mysqldump-php)

PHPackages © 2026

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