PHPackages                             folospace/socketio - 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. folospace/socketio

ActiveLibrary

folospace/socketio
==================

:description

25PHP

Since Mar 27Pushed 7y ago1 watchersCompare

[ Source](https://github.com/folospace/socketio)[ Packagist](https://packagist.org/packages/folospace/socketio)[ RSS](/packages/folospace-socketio/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Socketio
========

[](#socketio)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b5b03e471bb0a8bb24df8431fde89f1917786e64ef880440b7ea0271843be185/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6c6f73706163652f736f636b6574696f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/folospace/socketio)[![Total Downloads](https://camo.githubusercontent.com/a0d44572f4dc9e32cae911f43473e4f0b9902f91604a5e60ddf8ae937f734cce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f6c6f73706163652f736f636b6574696f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/folospace/socketio)[![Build Status](https://camo.githubusercontent.com/24272571a572d78e1d69e63ee694124add0506e0549b04cb3f25f9c88dbce794/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f666f6c6f73706163652f736f636b6574696f2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/folospace/socketio)

A simple socketio server for Laravel.

Require php package [*predis*](https://github.com/nrk/predis).

Require php extension [*swoole*](https://github.com/swoole/swoole-src).

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

[](#installation)

Via Composer

```
$ composer require folospace/socketio
```

Usage
-----

[](#usage)

### server commands

[](#server-commands)

```
$ php artisan socketio start        //start server
$ php artisan socketio start --d    //start server daemonize
$ php artisan socketio stop         //stop server
$ php artisan socketio status       //server status
```

### register events

[](#register-events)

```
namespace App\Providers;

use Folospace\Socketio\Facades\Socketio;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        if (php_sapi_name() == 'cli') {
            Socketio::on('connection', function ($socket, $request) {
                print_r($request);
                echo 'connection:'.$socket->id.PHP_EOL;
            });

            Socketio::on('disconnect', function ($socket) {
                echo 'disconnect:'.$socket->id.PHP_EOL;
                //$this->onLogout($socket->id);
            });

            Socketio::on('login', function ($socket, $data) {
                $userId = $data['token']; //parse user id from client token
                if ($userId) {
                    //Socketio::login($socket->id, $userId);
                    $socket->emit('login', ['error_code' => 0, 'message' => 'login success']);
                } else {
                    $socket->emit('login', ['error_code' => 1, 'message' => 'invalid token']);
                }
            });

            Socketio::on('test', function ($socket, $data) {
                $socket->emit('test', 'hello there');
            });

            Socketio::on('private_event_with_ack', function ($socket, $data, $ack) {
                if (Socketio::getUserIdByClient($socket->id)) {
                    //do sth after login.
                    if ($ack) {
                        $ack('done');
                    }
                } else {
                    //disconnect guest.
                    $socket->disconnect();
                }
            });
        }
    }
}
```

### Test

[](#test)

```
use Folospace\Socketio\Facades\Socketio;

//after socket login, send data to user from anywhere
Socketio::emitToUser($userId, 'test', ['message' => 'I am server']);

//after server start, connect to local server
Route::get('/', function () {
    $client = new \Folospace\Socketio\Foundation\SocketioClient('127.0.0.1', 3001);

    $client->emit('test', 'hello');
    //sleep(3);
    $ret = $client->receive();

    dd($ret);
});
```

Publish and modify config
-------------------------

[](#publish-and-modify-config)

```
$ php artisan vendor:publish --provider="Folospace\Socketio\SocketioServiceProvider"
```

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

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

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [magacy](https://github.com/folospace)
- [All Contributors](../../contributors)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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/098efa560ae557db2efbdb920039ecd0cd5d968573ee952e408451cde3ad5b7d?d=identicon)[folospace](/maintainers/folospace)

---

Tags

laravelsocket-iosocket-io-server

### Embed Badge

![Health badge](/badges/folospace-socketio/health.svg)

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

PHPackages © 2026

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