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. [HTTP &amp; Networking](/categories/http)
4. /
5. ga/socket

ActiveLibrary[HTTP &amp; Networking](/categories/http)

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 3w 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 13% 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://avatars.githubusercontent.com/u/15990961?v=4)[CoderLiu](/maintainers/liuzexin)[@liuzexin](https://github.com/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)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25025.5M80](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.2M6.5k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k20.0k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87930.4k113](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.3M84](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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