PHPackages                             phgraph/graph - 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. phgraph/graph

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

phgraph/graph
=============

Mathematical Graphing Library

v1.3.0(6y ago)13163[2 PRs](https://github.com/phgraph/graph/pulls)MITPHPPHP ^7.2.0

Since Apr 3Pushed 3y ago2 watchersCompare

[ Source](https://github.com/phgraph/graph)[ Packagist](https://packagist.org/packages/phgraph/graph)[ Docs](https://github.com/phgraph/graph)[ RSS](/packages/phgraph-graph/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (5)Dependencies (6)Versions (11)Used By (0)

[![Build Status](https://camo.githubusercontent.com/070c73244911f3eab4fd48f2b178e6b40258ade10d6c6b985f08e9f8fe62e06d/68747470733a2f2f7472617669732d63692e6f72672f706867726170682f67726170682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phgraph/graph)[![Coverage Status](https://camo.githubusercontent.com/1924b5b0b83952573cededaec6d851154160811c95bb10901466e537dc6855c8/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f706867726170682f67726170682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/phgraph/graph?branch=master)[![StyleCI](https://camo.githubusercontent.com/7d78c1ef73d6100415d391a04596032c779a4fd8b6b93a5c71f4d1d70fb6d143/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3137363036363330362f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/176066306)[![Maintainability](https://camo.githubusercontent.com/ecd7a148a646adde3fe91ae309d5e4dfa3700b0a20ee6cf502c29390ad973b50/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f32663139343132393365386634333161336339642f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phgraph/graph/maintainability)

phgraph/graph
=============

[](#phgraphgraph)

PHGraph is a modern mathematical graph/network library written in PHP.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require phgraph/graph
```

Usage
-----

[](#usage)

### Creation and Search

[](#creation-and-search)

```
use PHGraph\Graph;
use PHGraph\Search\BreadthFirst;
…

$graph = new Graph;
$columbus = $graph->newVertex([
    'name' => 'Columbus',
]);
$cleveland = $graph->newVertex([
    'name' => 'Cleveland',
]);
$cincinnati = $graph->newVertex([
    'name' => 'Cincinnati',
]);

$columbus->createEdge($cleveland);
$columbus->createEdge($cincinnati);

$search = new BreadthFirst($cincinnati);
if ($search->hasVertex($cleveland)) {
    echo "We can get from Cincinnati to Cleveland\n";
} else {
    echo "We can’t get from Cincinnati to Cleveland\n";
}
```

### Graph drawing

[](#graph-drawing)

This library has support for visualizing graphs as images using [GraphViz](http://www.graphviz.org/) "Graph Visualization Software". You will need GraphViz installed on your system for this to work.

```
use PHGraph\Graph;
use PHGraph\GraphViz\GraphViz;
…

$graph = new Graph;
$columbus = $graph->newVertex([
    'name' => 'Columbus',
]);
$cleveland = $graph->newVertex([
    'name' => 'Cleveland',
]);
$cincinnati = $graph->newVertex([
    'name' => 'Cincinnati',
]);
$columbus->createEdge($cleveland);
$columbus->createEdge($cincinnati);

$graphviz = new GraphViz($graph);
// open the image on your system
$graphviz->display();
```

output:

[![display output](/example/simple.png?raw=true)](/example/simple.png?raw=true)

### Algorithms

[](#algorithms)

A graph library is rather boring without the ability to use algorithms on it, here is a list of the currently supported ones:

- [Search](https://en.wikipedia.org/wiki/Graph_traversal)
    - [Depth first](https://en.wikipedia.org/wiki/Depth-first_search)
    - [Breadth first](https://en.wikipedia.org/wiki/Breadth-first_search)
- [Shortest path](https://en.wikipedia.org/wiki/Shortest_path_problem)
    - [Dijkstra](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm)
    - [Moore-Bellman-Ford](https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm)
    - [Least Hops](https://en.wikipedia.org/wiki/Best-first_search)
- [Minimum Spanning Tree](https://en.wikipedia.org/wiki/Minimum_spanning_tree)
    - [Kruskal’s algorithm](https://en.wikipedia.org/wiki/Kruskal%27s_algorithm)
    - [Prim’s algorithm](https://en.wikipedia.org/wiki/Prim%27s_algorithm)
- [Traveling Salesman Problem](https://en.wikipedia.org/wiki/Travelling_salesman_problem)
    - [Nearest Neighbor](https://en.wikipedia.org/wiki/Nearest_neighbour_algorithm)

Development
===========

[](#development)

Installing dependencies
-----------------------

[](#installing-dependencies)

You will need [Composer](https://getcomposer.org/) for the development dependencies. Once you have that, run the following

```
$ composer install
```

Running tests
-------------

[](#running-tests)

You can run the current test suite with the following command

```
$ composer test
```

For static analysis of the code run the following

```
$ composer analyse
```

Bug Reports
-----------

[](#bug-reports)

Bug reports for the current release version can be opened in this repository’s [issue tracker](https://github.com/phgraph/graph/issues).

Thanks
------

[](#thanks)

this was heavily inspired by [graphp/graph](https://github.com/graphp/graph).

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Recently: every ~55 days

Total

7

Last Release

2258d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ed2a49d248735e5f7b756d632644eeeb44df94ef808bb8578ff998b212917ff?d=identicon)[veetor](/maintainers/veetor)

---

Top Contributors

[![sporchia](https://avatars.githubusercontent.com/u/349353?v=4)](https://github.com/sporchia "sporchia (42 commits)")

---

Tags

graph-algorithmsgraph-search-algorithmsgraphvizphpshortest-path-algorithmnetworkgraphmathematicalvertexedge

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phgraph-graph/health.svg)

```
[![Health](https://phpackages.com/badges/phgraph-graph/health.svg)](https://phpackages.com/packages/phgraph-graph)
```

###  Alternatives

[clue/graph

GraPHP is the mathematical graph/network library written in PHP.

7144.4M43](/packages/clue-graph)[graphp/graph

GraPHP is the mathematical graph/network library written in PHP.

714305.2k4](/packages/graphp-graph)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[phonetworks/pho-lib-graph

A general purpose graph library in PHP

556.0k1](/packages/phonetworks-pho-lib-graph)[illuminate/process

The Illuminate Process package.

44813.9k96](/packages/illuminate-process)[fab2s/nodalflow

A PHP Nodal WorkFlow

16369.0k1](/packages/fab2s-nodalflow)

PHPackages © 2026

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