Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Lib that help create simple socket client, server on php
Latest commit 6d22c7d @aysheka Merge pull request #9 from Fastto/writeExeptionFix
fix exeption type in write method
Failed to load latest commit information.
src/Aysheka/Socket fix exeption type in write method
test Format code
.gitignore ignored composer.lock
composer.json + Format code Update

This library provide functionality for working with socket

Notice: 1. Library was tested only on TCP, IP4, Stream connection 2. You can find samples(server, client) in test directory

How connect to server

use Symfony\Component\EventDispatcher\EventDispatcher;
use Aysheka\Socket\Client\Client;
use Aysheka\Socket\Address\IP4;
use Aysheka\Socket\Type\Stream;
use Aysheka\Socket\Transport\TCP;

$client = new Client('', 8089, new IP4(), new Stream(), new TCP(), new EventDispatcher());

And thats all

How create a server

use Aysheka\Socket\Client;
use Aysheka\Socket\Type\Stream;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Aysheka\Socket\Server\Event\NewConnectionEvent;
use Aysheka\Socket\Server\Server;
use Aysheka\Socket\Address\IP4;
use Aysheka\Socket\Transport\TCP;

$eventDispatcher = new EventDispatcher();

$eventDispatcher->addListener(NewConnectionEvent::getEventName(), function (NewConnectionEvent $event) {

    $socket = $event->getSocket();

    $socket->write("HELLO I'm test server\n");

    // Read bytes from socket if available
    while ($read = $socket->read()) {
        echo "Read data: [{$read}]";

$server = new Server('', 8089, new IP4(), new Stream(), new TCP(), $eventDispatcher);

Something went wrong with that request. Please try again.