PHPackages                             phunkie/effect - 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. phunkie/effect

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

phunkie/effect
==============

A functional effects library for PHP inspired by Scala's cats-effect

1.2.0(3mo ago)11993MITPHPPHP ^8.2 || ^8.3 || ^8.4 || ^8.5CI passing

Since Jun 14Pushed 3mo agoCompare

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

READMEChangelog (9)Dependencies (5)Versions (10)Used By (3)

Phunkie Effect
==============

[](#phunkie-effect)

[![CI](https://github.com/phunkie/effect/actions/workflows/ci.yml/badge.svg)](https://github.com/phunkie/effect/actions)[![Latest Version](https://camo.githubusercontent.com/a6bb577f9680464a32d3def0d9681abef1ead8ff978f4cdef96784d19df7de52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068756e6b69652f6566666563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phunkie/effect)[![Total Downloads](https://camo.githubusercontent.com/dbc89f6db43cbe2093af5838e3739dcf37e867700b71f3bde30e047743a81e3c/68747470733a2f2f706f7365722e707567782e6f72672f7068756e6b69652f6566666563742f646f776e6c6f616473)](https://packagist.org/packages/phunkie/effect)[![License](https://camo.githubusercontent.com/5c25fdd815ee2837920b93d326c7f974d4e2b1cc6c10d15cd32272d4cc1def2d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068756e6b69652f6566666563742e7376673f7374796c653d666c61742d737175617265)](https://github.com/phunkie/effect/blob/main/LICENSE)[![PHP Version](https://camo.githubusercontent.com/461a8c8d24b9351fba62265ee4b565a59ed0365770067cb385f2b1be76153911/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068756e6b69652f6566666563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phunkie/effect)

A functional effects library for PHP inspired by Scala's cats-effect. Phunkie Effect provides a way to manage side effects in a purely functional way, making your code more predictable, testable, and maintainable.

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

[](#installation)

```
composer require phunkie/effect
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher

Basic Usage
-----------

[](#basic-usage)

### IO Monad

[](#io-monad)

The `IO` monad is the primary way to handle effects in Phunkie Effects. It allows you to wrap side effects in a pure functional context. Following Phunkie's design philosophy, we use traits to extend types and functions to construct and manipulate them.

```
use Phunkie\Effect\Functions\io\io;
use Phunkie\Effect\IO\IO;

// Create an IO from a pure value using the io function
$pure = io(42);

// Create an IO from a side effect
$effect = io(function() {
    return file_get_contents('data.txt');
});

// Map over an IO using the FunctorOps trait
$mapped = $effect->map(function($content) {
    return strtoupper($content);
});

// Chain IOs using the MonadOps trait
$chained = $effect->flatMap(function($content) {
    return io(function() use ($content) {
        return file_put_contents('output.txt', $content);
    });
});
```

### Async Execution with start()

[](#async-execution-with-start)

The `start()` method allows you to fork computations into background fibers, enabling fire-and-forget patterns:

```
use function Phunkie\Effect\Functions\io\io;

// Define an async operation
$sendEmail = io(function() use ($user) {
    mail($user->email, 'Welcome!', '...');
    return 'sent';
});

// Fork to background and continue immediately
$program = $sendEmail
    ->start()  // Returns IO
    ->map(function($handle) {
        // Continue with other work...
        return 'Email queued';
    });

// Or await the result later
$program = $sendEmail
    ->start()
    ->flatMap(function($handle) {
        // Do other work here...
        $otherWork = io(fn() => 'other work done');

        return $otherWork->map(function($result) use ($handle) {
            // Now wait for email to finish
            $emailResult = $handle->await();
            return [$result, $emailResult];
        });
    });

// Custom execution context
use Phunkie\Effect\Concurrent\ParallelExecutionContext;

$heavyComputation = io(fn() => processLargeDataset());
$handle = $heavyComputation
    ->start(new ParallelExecutionContext())  // Use parallel threads
    ->unsafeRun();
```

Features
--------

[](#features)

- Pure functional effect handling
- Type-safe IO operations
- Composable effect chains
- Error handling through Either
- Resource management
- **Async execution with `start()`** - Fork computations to background fibers
- **Custom execution contexts** - Control how effects are executed

Why Phunkie Effects?
--------------------

[](#why-phunkie-effects)

- **Type Safety**: Catch errors at compile time
- **Referential Transparency**: Same input always produces the same output
- **Testability**: Easier to test pure functions
- **Composability**: Build complex programs from simple, pure functions
- **Resource Management**: Safe handling of resources like files and network connections

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments
---------------

[](#acknowledgments)

- Inspired by [cats-effect](https://typelevel.org/cats-effect/)
- Built on top of [Phunkie](https://github.com/phunkie/phunkie)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance82

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

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

Total

9

Last Release

93d ago

Major Versions

v0.4.2 → 1.0.02025-12-08

PHP version history (4 changes)v0.1PHP &gt;=8.1

v0.4.1PHP &gt;=8.2

1.0.0PHP ^8.2 || ^8.3 || ^8.4

1.2.0PHP ^8.2 || ^8.3 || ^8.4 || ^8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/70713?v=4)[md](/maintainers/md)[@md](https://github.com/md)

---

Top Contributors

[![MarcelloDuarte](https://avatars.githubusercontent.com/u/144535?v=4)](https://github.com/MarcelloDuarte "MarcelloDuarte (75 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phunkie-effect/health.svg)

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

PHPackages © 2026

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