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

ActiveLibrary

ga/socket
=========

Socket server and client

16PHP

Since Jan 20Pushed 9y ago1 watchersCompare

[ Source](https://github.com/liuzexin/GASocket)[ Packagist](https://packagist.org/packages/ga/socket)[ RSS](/packages/ga-socket/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

GASocket is a easy(with block) for PHP socket communication.
============================================================

[](#gasocket-is-a-easywith-block-for-php-socket-communication)

\#Introduction

The `SocketClient` class is used to create a socket communication from server.`SocketServer` class is used to listen the server port and create socket communication for client request.

GASocket mainly use the 'block' to receive callback.`socket_*` function is the core of GASocket.

When you use the GASocket as server, sever receive the `quit` data form clinet, this client connection will disconnect.Or receive the `shutdown` data from client, server will close in listening port and program execution is completed.

\#Installation

```
composer require ga/socket dev-master

```

\#Usage ##namespace `\ga\socket`

\##SocketConnection

**Config Params**`ip` : Connection ip address. `port` : Port. `callback` : When client receive the server's data ,this block will call. `domain`, `type`, `protocol` : According to [`socket_create()`](http://php.net/manual/en/function.socket-create.php) function to set up.(Default is TCP connection configuration). `sendTimeOut`,`recTimeOut` : According to [`socket_set_option()`](http://php.net/manual/en/function.socket-set-option.php) function to set up.(), these two params in seconds.

SocketClient Extends SocketConnection
-------------------------------------

[](#socketclient-extends-socketconnection)

**Config Params**`sync` : If `true` it was blocking mode.Default is `false` means it was 'nonblock' mode.
`sendData` : When connection is successful send the `sendData`.

**EXAMPLE 1:**

```
$soc = new SocketClient([
    'ip' => '127.0.0.1',
    'port' => '30000'
]);
$soc->sendData = 'data' . "\n";
$soc->callback = function($data, $socket) use ($soc){
    echo 'Client receive:' . $data ."\n";
};
$soc->start();
```

**NOTICE**In the client `$soc` is the same of `$socket`.

\##SocketServer Extends SocketConnection **Config Params**`singleMode` : The `true` means that the max number of clients is only one. `maxClients` : The max number of the clients to connect.(If `singleMode` was `true` ,this param is invalid, and it's default value is 10.)

**EXAMPLE 2:**

```
$soc = new SocketServer([
    'singleModel' =>true
]);
$soc->callback = function ($data, $socket) use($soc){

    echo 'server receive:' . $data ."\n";
    $soc->send($socket, 'Server has receive data'."\n\r");
};
$soc->start();
```

**NOTICE**`$soc` is the server socket variable, `$socket` is the current connected client socket.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/46b02b02f139162e86f44608047a7f45ad5744f29e02b14d5bfaf1c8233d0b9a?d=identicon)[liuzexin](/maintainers/liuzexin)

---

Top Contributors

[![liuzexin](https://avatars.githubusercontent.com/u/15990961?v=4)](https://github.com/liuzexin "liuzexin (2 commits)")

### Embed Badge

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

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

PHPackages © 2026

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