PHPackages                             wilaak/datastar-swoole - 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. wilaak/datastar-swoole

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

wilaak/datastar-swoole
======================

Datastar SDK for Swoole.

v1.0.0-RC.1(7mo ago)329MITPHPPHP &gt;=8.2

Since Sep 26Pushed 3mo agoCompare

[ Source](https://github.com/wilaak/datastar-swoole)[ Packagist](https://packagist.org/packages/wilaak/datastar-swoole)[ RSS](/packages/wilaak-datastar-swoole/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

[![](https://camo.githubusercontent.com/0463423256b1e3d458414955ddbb6efd921b5ed49e9aa3b4fc8df555e271cd82/68747470733a2f2f646174612d737461722e6465762f7374617469632f696d616765732f726f636b65742d353132783531322e706e67)](https://camo.githubusercontent.com/0463423256b1e3d458414955ddbb6efd921b5ed49e9aa3b4fc8df555e271cd82/68747470733a2f2f646174612d737461722e6465762f7374617469632f696d616765732f726f636b65742d353132783531322e706e67)

Datastar SDK for Swoole PHP
===========================

[](#datastar-sdk-for-swoole-php)

This package offers an SDK for working with [Datastar](https://data-star.dev) in [Swoole](https://wiki.swoole.com/en/#/). It is a simple wrapper of the [Official PHP SDK](https://github.com/starfederation/datastar-php).

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

[](#installation)

First you must install the Swoole PHP extension. Please refer to the [documentation](https://wiki.swoole.com/en/#/environment?id=pecl).

```
composer require wilaak/datastar-swoole

```

Usage Examples
--------------

[](#usage-examples)

In Swoole, each request is put in its own [coroutine](https://wiki.swoole.com/en/#/coroutine), allowing you to write PHP code in a standard blocking way.

Note

To ensure proper behavior of built-in functions, you must enable coroutine hooks. This is achieved by calling `\Swoole\Runtime::enableCoroutine()` at the start of your program.

```
use Swoole\Http\{Server, Request, Response};
use Swoole\Runtime;
use DatastarSwoole\{SSE, ElementPatchMode};

// After this line of code, file operations, sleep, Mysqli, PDO, streams, etc., all become asynchronous IO.
Runtime::enableCoroutine();

$http = new Server("0.0.0.0", 8082);

$http->on('request', function (Request $req, Response $res) {
    $sse = new SSE($req, $res);

    $message = "Hello, World!";
    foreach (str_split($message) as $i => $char) {
        $sse->patchElements("" . substr($message, 0, $i + 1) . "");
        sleep(1);
    }
});

$http->start();
```

Note

When in a long-running request, it's important to close the connection once the user disconnects so as to not keep running forever:

```
$http->on('request', function (Request $req, Response $res) {
    $sse = new SSE($req, $res);
    while (true) {
        $sse->patchElements("" . time() . "");
        $success = $response->write('ping: hello');
        if ($success === false) {
            break;
        }
        sleep(1);
    }
});
```

This example covers most of the usage possible with this SDK:

```
use Swoole\Http\{Server, Request, Response};
use Swoole\Runtime;
use DatastarSwoole\{SSE, ElementPatchMode};

// After this line of code, file operations, sleep, Mysqli, PDO, streams, etc., all become asynchronous IO.
Runtime::enableCoroutine();

$http = new Server("0.0.0.0", 8082);

$http->on('request', function (Request $request, Response $response) {

    // Creates a new SSE instance.
    $sse = new SSE($request, $response);

    // Reads signals from the request.
    $signals = $sse->readSignals();

    // Patches elements into the DOM.
    $sse->patchElements('', [
        'selector' => '#my-div',
        'mode' => ElementPatchMode::Append,
        'useViewTransition' => true,
    ]);

    // Removes elements from the DOM.
    $sse->removeElements('#my-div', [
        'useViewTransition' => true,
    ]);

    // Patches signals.
    $sse->patchSignals(['foo' => 123], [
        'onlyIfMissing' => true,
    ]);

    // Executes JavaScript in the browser.
    $sse->executeScript('console.log("Hello, world!")', [
        'autoRemove' => true,
        'attributes' => [
            'type' => 'application/javascript',
        ],
    ]);

    // Redirects the browser by setting the location to the provided URI.
    $sse->location('/guide');
});

$http->start();
```

License
-------

[](#license)

MIT

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance72

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

228d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/01a8e7032a702e24d36f4d23aeee183576ddbeac68f17aacfa89786a439ab565?d=identicon)[wilaak](/maintainers/wilaak)

---

Top Contributors

[![wilaak](https://avatars.githubusercontent.com/u/54738571?v=4)](https://github.com/wilaak "wilaak (24 commits)")

---

Tags

datastarswoole

### Embed Badge

![Health badge](/badges/wilaak-datastar-swoole/health.svg)

```
[![Health](https://phpackages.com/badges/wilaak-datastar-swoole/health.svg)](https://phpackages.com/packages/wilaak-datastar-swoole)
```

PHPackages © 2026

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