Reactive extensions for PHP.

Related tags

Event Rx.PHP
Overview

This package is abandoned. Use https://github.com/ReactiveX/RxPHP instead

Rx.PHP

Reactive extensions for PHP. The reactive extensions for PHP are a set of libraries to compose asynchronous and event-based programs using observable collections and LINQ-style query operators in PHP.

Build Status

Quick start for demos

Install dependencies using composer.

$ composer.phar install

Have fun running the demos in /demo.

Demo application

rxphp-chat, a demo chat application using Rx.PHP.

License

  • Rx.PHP is licensed under the MIT License - see the LICENSE file for details
  • I am providing code in this repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not from my employer (Facebook).
Comments
  • Supported PHP versions

    Supported PHP versions

    Rx.PHP currently supports PHP 5.3. https://github.com/asm89/Rx.PHP/pull/6 changes the requirement to PHP 5.4, but that version is already EOL (http://php.net/eol.php).

    How about raising the minimal supported version to either 5.5 or 5.6 and up?

    cc @davidwdan @cboden @mbonneau @Ocramius

    enhancement question 
    opened by asm89 5
  • Segmentation Fault

    Segmentation Fault

    The following code will cause php to seg fault:

    $observable = new Rx\Observable\ArrayObservable(range(1, 10000));
    $observable->subscribe(new \Rx\Observer\CallbackObserver());
    

    I'm guessing that this has something to do with the recursive actions in the ImmediateScheduler blowing the stack, because it works fine with the VirtualTimeScheduler.

    opened by davidwdan 3
  • Replace select and selectMany with map and flatMap

    Replace select and selectMany with map and flatMap

    Every other implementation of Rx, other than RxNet, is now using map and flatMap. We should probably consider changing it or at least making an alias.

    opened by davidwdan 2
  • BaseObservable::fromArray() issues

    BaseObservable::fromArray() issues

    If you subscribe without a scheduler to the AnonymousObservable returned by BaseObservable::fromArray, the script dies.

    Fatal error: Call to a member function scheduleRecursive() on null in  rx.php/lib/Rx/Observable/BaseObservable.php on line 223
    

    Also, fromArray is called in BaseObservable::merge with a scheduler argument when it doesn't take an argument.

    Example code:

    Failure on merge:

    require_once __DIR__ . '/vendor/autoload.php';
    
    $aa = [1,2,3,4];
    $ab = [5,6,7,8];
    
    $oa = new \Rx\Observable\ArrayObservable($aa);
    $ob = new \Rx\Observable\ArrayObservable($ab);
    
    $oa->merge($ob)->subscribeCallback(function ($x) {
        echo "$x\n";
    });
    

    Failure with fromArray:

    require_once __DIR__ . '/vendor/autoload.php';
    
    $aa = [1,2,3,4];
    
    $oa = \Rx\Observable\BaseObservable::fromArray($aa);
    
    $oa->subscribeCallback(function ($x) {
        echo "$x\n";
    });
    
    opened by mbonneau 2
  • Update composer php requirement to 5.5 and up

    Update composer php requirement to 5.5 and up

    PHP 5.5 is the oldest still supported PHP version. It does not make sense to support older versions. PHP 7 will be released soon, so let's start explicitly supporting it.

    Fixes #7

    opened by asm89 1
  • Implement Your Own Operators

    Implement Your Own Operators

    With the current version of Rx.PHP, if you want to implement a custom operator, you need to add it to BaseObservable.

    I propose that we take a page from RxJava and add a lift operator, which would allow custom operators to be added to the chain.

    For Example:

    
    $observable = new Rx\Observable\ArrayObservable(array(21, 21, 42));
    $observable
        ->select(function($elem) { return $elem * 2; })
        ->lift(new DistinctUntilChangedOperator())
        ->subscribe($stdoutObserver);
    
    

    I've been working on an implementation of this here: https://github.com/davidwdan/Rx.PHP/compare/master...operators?diff=unified&name=operators

    It includes the lift operator along with tap, never and distinctUntilChanged.

    If this is a direction you're interested in going, let me know and I'll create PRs.

    opened by davidwdan 1
  • ArrayObservable and fromArray Inconsistencies

    ArrayObservable and fromArray Inconsistencies

    ArrayObservable uses array_shift instead of an index to access the current value, which makes it about 10 times slower than fromArray

    I can't think of any reasons why we should have both implementations. The static method should return a new instance of ArrayObservable, which should use the index instead of array_shift.

    Another issue, is that fromArray only works with a numeric index. If you use an associative array, it fails.

    We should use array_keys to get the actual keys, and then do this: $observer->onNext($array[$keys[$count]]);

    The key will be lost, which will be okay in most cases. If you need to preserve the keys, you can use the pairs operator.

    opened by davidwdan 0
  • Operators share properties across subscriptions

    Operators share properties across subscriptions

    I would expect the output of the code below:

    $outputObserver = new \Rx\Observer\CallbackObserver(function ($x) { echo $x . "\n"; });
    $outputObserver2 = new \Rx\Observer\CallbackObserver(function ($x) { echo $x . "\n"; });
    
    $a = [1,2,3,4,5];
    
    $o = \Rx\Observable\BaseObservable::fromArray($a);
    
    $count = $o->count();
    
    $count->subscribe($outputObserver);
    
    $count->subscribe($outputObserver2);
    

    to be:

    5
    5
    

    but it actually outputs:

    5
    10
    

    Because there is only one instance of the operator created, the same instance is being used for both subscriptions and it counts twice.

    To fix this, the argument to lift should probably be an operator factory so every subscription gets a different instance.

    And lift would change to:

        public function lift(callable $operatorFactory)
        {
            return new AnonymousObservable(function (ObserverInterface $observer, SchedulerInterface $schedule) use ($operatorFactory) {
                $operator = $operatorFactory();
                return $operator($this, $observer, $schedule);
            });
        }
    
    opened by mbonneau 0
  • Connectable Observables

    Connectable Observables

    I've implemented all of the connectable observables from RxJS. Since they're interdependent, it probably makes sense to handle them as one PR, but I can split them up if it's too much to review at once.

    Before I create the PR, I need some feedback on the best way to handle the operators that can take a value or factory as the same argument. See:

    https://github.com/davidwdan/Rx.PHP/blob/connectable_observables/lib/Rx/Observable/BaseObservable.php#L650 https://github.com/davidwdan/Rx.PHP/blob/connectable_observables/lib/Rx/Observable/BaseObservable.php#L697

    Also, some of the tests are skipped because zip hasn't been implemented yet. @JMB3 is working on that.

    opened by davidwdan 6
Owner
Alexander
Alexander
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.3.

Workerman What is it Workerman is an asynchronous event-driven PHP framework with high performance to build fast and scalable network applications. Wo

walkor 10.2k Jan 4, 2023
Event-driven, non-blocking I/O with PHP.

Event-driven, non-blocking I/O with PHP. ReactPHP is a low-level library for event-driven programming in PHP. At its core is an event loop, on top of

ReactPHP 8.5k Jan 8, 2023
A non-blocking concurrency framework for PHP applications. 🐘

Amp is a non-blocking concurrency framework for PHP. It provides an event loop, promises and streams as a base for asynchronous programming. Promises

Amp 3.8k Jan 6, 2023
Icicle is a PHP library for writing asynchronous code using synchronous coding techniques

Icicle is now deprecated in favor of Amp v2.0. This version is is currently under development, but close to release. The v2.0 branches are amp_v2 in a

icicle.io 1.1k Dec 21, 2022
Événement is a very simple event dispatching library for PHP.

Événement Événement is a very simple event dispatching library for PHP. It has the same design goals as Silex and Pimple, to empower the user while st

Igor 1.2k Jan 4, 2023
Asynchronous coroutines for PHP 7.

Recoil An asynchronous coroutine kernel for PHP 7. composer require recoil/recoil The Recoil project comprises the following packages: recoil/api - T

Recoil 787 Dec 8, 2022
A pragmatic event sourcing library for PHP with a focus on developer experience.

EventSaucePHP EventSauce is a somewhat opinionated, no-nonsense, and easy way to introduce event sourcing into PHP projects. It's designed so storage

EventSauce 685 Dec 31, 2022
PHP 7.4 EventStore Implementation

Prooph Event Store Common classes and interface for Prooph Event Store implementations. Installation You can install prooph/event-store via composer b

null 532 Dec 9, 2022
Golang's defer statement for PHP

PHP Defer A defer statement originally comes from Golang. This library allows you to use defer functionality in PHP code. Usage <?php defer($context,

null 249 Dec 31, 2022
🚀 Coroutine-based concurrency library for PHP

English | 中文 Swoole is an event-driven asynchronous & coroutine-based concurrency networking communication engine with high performance written in C++

Swoole Project 17.7k Jan 5, 2023
PHP Application using DDD CQRS Event Sourcing with Hexagonal Architecture

PHP Application using DDD CQRS Event Sourcing with Hexagonal Architecture Application built with Ecotone Framework and powered by integrations with Pr

EcotoneFramework 65 Dec 27, 2022
Revolt is a rock-solid event loop for concurrent PHP applications.

Revolt is a rock-solid event loop for concurrent PHP applications.

Revolt PHP 586 Jan 2, 2023
Reactive extensions for PHP

RxPHP Reactive extensions for PHP. The reactive extensions for PHP are a set of libraries to compose asynchronous and event-based programs using obser

ReactiveX 1.6k Dec 12, 2022
A magic PHP framework. Build reactive web apps without writing HTML, CSS, or JavaScript! Powered by Tailwind, Alpine, Laravel, & Livewire.

Malzahar A magic PHP framework. Build reactive web apps without writing HTML, CSS, or JavaScript! Powered by Tailwind, Alpine, Laravel, & Livewire. Re

null 26 Nov 17, 2022
Viewi for Laravel: Build full-stack and completely reactive user interfaces with PHP.

[WIP] Laravel Viewi This is just a proof-of-concept. Don't use it in production! Viewi for Laravel: Build full-stack and completely reactive user inte

Protone Media 5 Jan 26, 2022
Reactive Form Builder for Vue.js with Laravel Support

Dynamic Form Builder for Laravel with Vue.js Create even the most complex forms with ease, using two-sided validation, eloquent, nested elements, cond

Laraform 340 Dec 31, 2022
Framework X – the simple and fast micro framework for building reactive web applications that run anywhere.

Framework X Framework X – the simple and fast micro framework for building reactive web applications that run anywhere. Quickstart Documentation Tests

Christian Lück 620 Jan 7, 2023
GitHub action to setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer...

Setup PHP in GitHub Actions Setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer in GitHub

Shivam Mathur 2.4k Jan 6, 2023
GitHub action to setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer...

Setup PHP in GitHub Actions Setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer in GitHub

Shivam Mathur 2.4k Jan 6, 2023
True asynchronous PHP I/O and HTTP without frameworks, extensions, or annoying code. Uses the accepted Fibers RFC to be implemented into PHP 8.1

PHP Fibers - Async Examples Without External Dependencies True asynchronous PHP I/O and HTTP without frameworks, extensions, or annoying code behemoth

Cole Green 121 Jan 6, 2023