True coroutines for PHP>=8.1 without worrying about event loops and callbacks.

Overview

Moebius

Pure coroutines for PHP 8.1. To promises and callbacks needed. Just pure parallel PHP code inside coroutines.

Moebius Band: A loop with only one surface

Möbuus Loop


What is this?

Completely transparent coroutines thanks to PHP 8.1 Fibers. No complex nested callbacks or promise trees. Just plain old-school PHP code running asynchronously, like in GoLang.

The easiest way to bring your codebase up to speed with high performance event based concurrency. It's like Swoole, but without the extension.

Asynchronous IO

Moebius will transparently switch between your coroutines whenever you are reading or writing to disk - so you don't need to worry about special async versions of common commands like file_get_contents and such.

Like GoLang, not like JavaScript

The main thing that makes PHP a very productive language, is that you can do much with very simple, single-threaded code.

With Moebius, you don't have to change your coding style.

Old-school javascript

    // Do something 10 times, once every second
    let counter = 0;
    let i = setInterval(() => {
        console.log("Every second");
        if (counter === 10) {
            clearInterval(i);
        }
    }, 1000);

"Cool" javascript

Ecmascript has introduced the async/await keywords, but you can't use them wherever you want. Not good.

    // need to make a sleep() function
    function sleep(time) {
        return new Promise((resolve) => {
            setTimeout(resolve, time * 1000);
        }
    }

    async function count() {
        for (let i = 0; i < 10; i++) {
            console.log("Every second");
            await sleep(1);
        }
    }

    // You CAN'T use the `await` function everywhere

Very cool PHP 8.1

Just call your function with go() (globally asynchronously), or with await(go()) (locally asynchronously).

    use M\{go, sleep};

    // Do something 10 times, once every second
    go(function() {
        for ($i = 0; $i < 10; $i++) {
            echo "Every second\n";
            sleep(1);
        }
    });
You might also like...
PHP Event Emitter

InitPHP EventEmitter This library has been designed to emit events in its simplest and simplest form. Requirements PHP 5.6 or higher Installation comp

A "from scratch" PHP-based implementation of Event-Sourcing

In here, you will find a "from scratch" PHP-based implementation of Event-Sourcing, kept to a minimum on purpose, to allow workshop attendees to explore and experiment with its concepts.

Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time
Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time

Preview Order Confirmation Page for Magento 2 For Magento 2.0.x, 2.1.x, 2.2.x and 2.3.x Styling and testing Magento's order confirmation page can be a

It allows frontend developer to send ajax requests and return a custom information from the server without a php developer help

[Magento 1 Extension] It allows frontend developer to send ajax requests and return a custom information from the server without a php developer help (without any php code).

An Infection + Last Man Standing Event plugin written for OwnagePE

KitPvPEvent An Infection + Last Man Standing Event plugin written for OwnagePE This plugin was a speedcode. I kinda woke up really late on the day I w

Psalm plugin for patchlevel/event-sourcing

event-sourcing-psalm-plugin psalm plugin for event-sourcing library. installation composer require --dev patchlevel/event-sourcing-psalm-plugin confi

This library is an implementation of League\Event for Slim Framework

Slim Event Dispatcher This library is an implementation of League\Event for Slim Framework. This works with the latest version of Slim (V3). Installat

Notify instructors about unconfirmed event registrations.
Notify instructors about unconfirmed event registrations.

SAC Event Registration Reminder Folgende Idee: Es wird ein Reminder-Tool benötigt, welches Tourenleitende und Bergführer/innen per E-Mail daran erinne

A Laravel artisan based package to create the AWS (SES + SNS) infrastructure to receive email event notifications with Http/Https endpoint.
A Laravel artisan based package to create the AWS (SES + SNS) infrastructure to receive email event notifications with Http/Https endpoint.

Laravel SES Tracking Setup the AWS infrastructure to handle email events using SES/SNS and http/s endpoints with a single Laravel artisan command. Thi

Comments
  • Clarification: how to get returned values from closures

    Clarification: how to get returned values from closures

    First: excellent package! Very promising! Quick request for clarification: pardon my ignorance, if the closure inside Coroutine::go() returns a value, how do I use it after the execution? Thank you!!

    opened by capsandiego 1
  • Run multiple closures with call_user_func_array()

    Run multiple closures with call_user_func_array()

    Could you please explain why calling Coroutine::go() for each closure works and it doesn't if I use call_user_func_array() ?

    $closures = [];
    $closures[] = function()
    {
        echo "\nThis is the first closure";
    };
    
    $closures[] = function()
    {
        echo "\nThis is the second closure";
    };
    
    $a = \Moebius\Coroutine::go($closures[0]);
    $b = \Moebius\Coroutine::go($closures[1]);
    
    // ---------- Result ----------
    // This is the first closure
    // This is the second closure
    
    call_user_func_array(["\Moebius\Coroutine", "go"], $closures);
    // ---------- Result ----------
    // This is the first closure
    
    opened by capsandiego 0
  • Depricated notices after composer required

    Depricated notices after composer required

    I installed the package via composer however it's throwing deprecated warnings when the composer autoload is required.

    bash-5.1$ php -v
    PHP 8.1.6 (cli) (built: May 13 2022 23:04:22) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.1.6, Copyright (c) Zend Technologies
        with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies
    
    Deprecated: Return type of SplMinHeap@anonymous::compare($a, $b) should either be compatible with SplMinHeap::compare(mixed $value1, mixed $value2): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /code/vendor/moebius/loop/src/Util/TimerQueue.php on line 12
    
    Deprecated: Implicit conversion from float 964.7129991208203 to int loses precision in /code/vendor/moebius/loop/src/Drivers/NativeDriver.php on line 193
    
    opened by benrowe-chuffed 1
  • [Question] Examples showing performance benefits

    [Question] Examples showing performance benefits

    Hello, do you have any examples which shows that blocking functions are really paused and executed when result is available? I am talking about something like https://github.com/frodeborli/moebius/blob/master/examples/async-tcp/async-tcp.php but when executing for example 20 requests. I have tried to implement such test but I cannot get any results with execution time better than synchronous execution

    Have a good day! :)

    opened by rutek 5
Owner
Frode Børli
Frode Børli
λ Run PHP Coroutines & Fibers as-a-Service on the AWS Lambda.

λ Swoole Runtime for AWS Lambda Run PHP Coroutines & Fibers as-a-Service on the AWS Lambda. Getting started Create your Lambda function index.php <?ph

Leo Cavalcante 32 Dec 29, 2022
Class PHP Api อั่งเปา True Wallet

Description: API อั่งเปา True Wallet (Rework) Features: ตรวจสอบอั่งเปา ใช้อั่งเปา แสดงผลออกมาเป็น Json Example: <?php use M4h45amu7x\Voucher; require

null 11 Oct 4, 2022
An open source Minecraft server (true-og.net)

true-og An open source Minecraft server (true-og.net) Website forked from aviel900 https://www.spigotmc.org/resources/minecraft-one-page-template.5973

Alex Noyle 0 Nov 28, 2022
salah eddine bendyab 18 Aug 17, 2021
Command and event buses interface and logic.

CoreBus - Command and Event buses interfaces Discrete command bus and domain event dispatcher interfaces for message based architectured projects. Dis

Makina Corpus 0 Feb 7, 2022
Ecotone Framework is Service Bus Implementation. It enables message driven architecture and DDD, CQRS, Event Sourcing PHP

This is Read Only Repository To contribute make use of Ecotone-Dev repository. Ecotone is Service Bus Implementation, which enables message driven arc

EcotoneFramework 308 Dec 29, 2022
JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

Eboubaker Eboubaker 2 Jul 31, 2022
Implement event systems, signal slots, intercepting filters, and observers.

zend-eventmanager Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-eventmanager. zend-eventmanager is designed for the fol

Zend Framework 1.7k Dec 9, 2022
Because every Wedding RSVP website needs to follow DDD, CQRS, Hexagonal Architecture, Event Sourcing, and be deployed on Lambda.

Our Wedding Website Because every Wedding RSVP website needs to follow DDD, CQRS, Hexagonal Architecture, Event Sourcing, and be deployed on Lambda. ?

Edd Mann 3 Aug 21, 2022
A high-performance event loop library for PHP

?? A high-performance event loop library for PHP ??

workbunny 13 Dec 22, 2022