PHPackages                             videlalvaro/phacterl - 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. videlalvaro/phacterl

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

videlalvaro/phacterl
====================

Actor Model, in PHP

77228PHP

Since Mar 24Pushed 12y ago6 watchersCompare

[ Source](https://github.com/videlalvaro/phacterl)[ Packagist](https://packagist.org/packages/videlalvaro/phacterl)[ RSS](/packages/videlalvaro-phacterl/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Phacterl
========

[](#phacterl)

Implementation of The Actor Model in PHP.

[![https://raw.githubusercontent.com/videlalvaro/phacterl/master/actors.gif](https://raw.githubusercontent.com/videlalvaro/phacterl/master/actors.gif)](https://raw.githubusercontent.com/videlalvaro/phacterl/master/actors.gif)

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

[](#installation)

Add `"videlalvaro/phacterl": "dev-master"` to your `composer.json` `require` section.

Usage
-----

[](#usage)

Your *Actors* need to extend the abstract class Actor for example, and implement two methods: `Actor::init` and `Actor::receive`. For example:

```
class Counter extends Actor {
    public function init($args) {
        return array(
            'count' => 0
        );
    }

    public function receive() {
        return array('incr', 'get_count');
    }
}
```

The method `init` should return an array that would be the *State* of the process. The runtime system will take care of managing the process state.

The method `receive` should return an array with strings specifying to which *message tags* this process responds to.

In our case, the process `Counter` should also provide a method called `handle_incr` and another one called `handle_get_count`.

### Implementing the Handlers

[](#implementing-the-handlers)

A handler is a function that takes two parameters, a `Message` and the process `State` and returns a new state, like this:

```
class Counter extends Actor {
// snip

    public function handle_incr($msg, $state) {
        $state['counter'] += $msg['amount'];
        return $state;
    }

// snip
}
```

### Sending messages

[](#sending-messages)

To send a message, your actor can call the function `Actor::send`, which expects a *process id* and a `Message`. When creating a `Message` instance, you need to provide a `tag`, like `'count'` in this case, and the message data. The *tag* is used to dispatch to a message handler called `handle_`.

```
class Counter extends Actor {
// snip

    public function handle_get_count($msg, $state) {
        $pid = $msg['sender'];
        $this->send(
                $pid,
                new Message(
                    'count',
                    array('sender' => $this->self(), 'count' => $state['counter'])
                )
            );
        return $state;
    }

// snip
}
```

Then, once you to run your actors, first get an instance of the `Scheduler`, and *spawn* your actor, by passing in the class name and the initial parameters for the Actor's *init* function.

```
$scheduler = new Scheduler();
$pid = $scheduler->spawn('Counter', array());
$scheduler->run();
```

### Stopping the System

[](#stopping-the-system)

From inside an actor you can simply call `$this->stop()`. Otherwise call `$scheduler->stop()`.

Examples
--------

[](#examples)

On the demo folder you can find many examples which are implementations of the algorithms presented in the book [Distributed Algorithms for Message-Passing Systems](http://www.amazon.com/Distributed-Algorithms-Message-Passing-Systems-Michel/dp/3642381227/).

Why?
----

[](#why)

Because implementing these algorithms in Erlang would be too easy.

Also, why not:

[![https://raw.githubusercontent.com/videlalvaro/phacterl/master/shooting.gif](https://raw.githubusercontent.com/videlalvaro/phacterl/master/shooting.gif)](https://raw.githubusercontent.com/videlalvaro/phacterl/master/shooting.gif)

Is this an April's Fool Joke
----------------------------

[](#is-this-an-aprils-fool-joke)

According to my Julian Calendar, it's April's First here.

LICENSE
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2014 - Alvaro Videla

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0004e714a43d2715c05937cb68675f73497fcc8b38c146052eeaa9037be5a741?d=identicon)[videlalvaro](/maintainers/videlalvaro)

---

Top Contributors

[![videlalvaro](https://avatars.githubusercontent.com/u/30834?v=4)](https://github.com/videlalvaro "videlalvaro (24 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![Rican7](https://avatars.githubusercontent.com/u/742384?v=4)](https://github.com/Rican7 "Rican7 (1 commits)")

### Embed Badge

![Health badge](/badges/videlalvaro-phacterl/health.svg)

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

###  Alternatives

[htmlburger/carbon-fields

WordPress developer-friendly custom fields for post types, taxonomy terms, users, comments, widgets, options and more.

1.5k665.2k57](/packages/htmlburger-carbon-fields)[tightenco/tlint

Tighten linter for Laravel conventions

5271.2M34](/packages/tightenco-tlint)[dflydev/placeholder-resolver

Given a data source representing key =&gt; value pairs, resolve placeholders like ${foo.bar} to the value associated with the 'foo.bar' key in the data source.

14414.6M3](/packages/dflydev-placeholder-resolver)[pear/pear

This is the definitive source of PEAR's core files.

1161.7M20](/packages/pear-pear)[pragmarx/ia-collection

Laravel Illuminate Agnostic Collection

473.4M2](/packages/pragmarx-ia-collection)[binarycabin/laravel-uuid

A wrapper for webpatser/laravel-uuid with additional integration

86589.4k](/packages/binarycabin-laravel-uuid)

PHPackages © 2026

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