PHPackages                             programmis/socket-chat - 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. programmis/socket-chat

ActiveExtra

programmis/socket-chat
======================

Simple socket chat

0.2.9(8y ago)51.6k31MITPHPPHP &gt;=7

Since Oct 27Pushed 8y ago2 watchersCompare

[ Source](https://github.com/programmis/socket_chat)[ Packagist](https://packagist.org/packages/programmis/socket-chat)[ Docs](https://github.com/programmis/socket_chat)[ RSS](/packages/programmis-socket-chat/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (8)Versions (30)Used By (1)

**Installing**

*1) Download composer:*

```
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
```

*2) Install:*

```
php composer.phar require programmis/socket-chat
```

**Starting chat server**

```
$loader = require __DIR__ . '/vendor/autoload.php';

$server = new chat\Server();
$server->start();

```

**or in your project**

```
class Server extends \chat\Server
{
    /** @inheritdoc */
    public static function getConfigClass()
    {
        return "Your config class implemented
            from \chat\interfaces\ConfigInterface
            or extend from \chat\libs\Config";
        //return MyConfig::class;
    }
}

```

and in your config class

```
class MyConfig extends \chat\libs\Config
{
    //you can override any chat class
}

```

and to start

```
$server = new your\project\namespace\Server();

$server->start();
//or for you daemon
$server->tick(); //in your daemon loop method

```

[simple daemon provider](https://github.com/programmis/daemon-provider)and [how to connect this chat to YII2 framework](https://github.com/programmis/yii2-socket-chat)

**popular methods**

```
UserProcessor:createUser    //maybe init user from your database by $connection_info data
User:findOne                //find and return user in your database by user id
User:getAccessList          //return user ids list of access to send messages
User:getSendRight           //return user right for send messages
User:getInfo                //return array with user info
User:onConnect              //called if user connect
User:onDisconnect           //called if user disconnect
User:onChangeRecipient      //called if user change recipient
Message:getHistory          //find and return users messages in your database
Message:beforeSend          //called before send message
Message:afterSend           //called after send message
Chat:sendMessageText        //you may send any text message to user

```

**Client side**

```

```

*Init java constants*

```

    $(function () {

    });

```

*Settings*

```
socketChat.connection_type = "Maybe 'ws' or 'wss'"
socketChat.current_user_id = "Current user id in chat";
socketChat.socket_url = "You're server address : and port";
socketChat.send_on_enter = "If this true, then all messages sending by press on enter key, ctrl+enter default"
socketChat.recipient_id = 'Message recipient id, you can fill it before send messages';
socketChat.room = "Chat room name is required fill";
socketChat.hash = "You're secret hash for processing with UserProcessor";
socketChat.user_typing_timeout = "For auto disable user typing status";
socketChat.message_history_period = "For default request message history";

```

*Functions*

```
socketChat.open();                                  //open connect with server
socketChat.close();                                 //close connect with server
socketChat.setMessageAreaId(id);                    //set textarea id for messages
socketChat.send();                                  //send message from message_area to socketChat.recipient_id
socketChat.getUserList();                           //get all users in current room
socketChat.getUserInfo(user_id);                    //get info about user
socketChat.getMessageHistory(with_user_id, period); //get all messages for current user and with_user_id by period

```

*Events*

```
socketChat.onConnect            //called if chat connected to server
socketChat.onDisconnect         //call if chat disconnected with server
socketChat.onMessageRender      //called if render message with "message" in parameter
socketChat.onMessageListRender  //called if render message list with "message_list" in parameter
socketChat.onUserConnect        //called if user connect to chat with "user" in parameter
socketChat.onUserDisconnect     //called if user disconnect from chat with "user" in parameter
socketChat.onUserRemoved        //called if user removed from chat with "user" in parameter
socketChat.onAboutMeInfo        //about you info
socketChat.onUserInfo           //called if received user info with "user" in parameter
socketChat.onUserList           //called if user list received with "user_list" in parameter
socketChat.onUserTypingStart    //called if user start typing with "user_id" in parameter
socketChat.onUserTypingEnd      //called if user end typing with "user_id" in parameter

```

*For nginx ssl encrypt*

```
Server::$port = 1337;
Server::$proxy_port = 1338;
Server::$proxy_connection_type = 'wss';

server {
    server_name localhost _;
    listen 1338 ssl;
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    root /home/project.ru/web;
    location / {
        proxy_pass http://127.0.0.1:1337;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

```

*How to enable another config param see example*[how to connect this chat to YII2 framework](https://github.com/programmis/yii2-socket-chat)

**For example see index.php and socketChatDemo.js files**

*Sorry for my english*

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

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

Recently: every ~76 days

Total

29

Last Release

3138d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/26b0822e1e5fa564e6b8762213749f2ce5d3e13e6313c09c9da898ea0638e1a6?d=identicon)[programmis](/maintainers/programmis)

---

Top Contributors

[![programmis](https://avatars.githubusercontent.com/u/10850140?v=4)](https://github.com/programmis "programmis (45 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/programmis-socket-chat/health.svg)

```
[![Health](https://phpackages.com/badges/programmis-socket-chat/health.svg)](https://phpackages.com/packages/programmis-socket-chat)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k234.7M20.6k](/packages/friendsofphp-php-cs-fixer)[cboden/ratchet

PHP WebSocket library

6.4k21.4M239](/packages/cboden-ratchet)[react/react

ReactPHP: Event-driven, non-blocking I/O with PHP.

9.1k3.6M63](/packages/react-react)[laravel/reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.

1.5k9.4M48](/packages/laravel-reverb)[botman/botman

Create messaging bots in PHP with ease.

6.2k1.5M97](/packages/botman-botman)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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