PHPackages                             jgswift/qtcp - 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. jgswift/qtcp

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

jgswift/qtcp
============

Web socket server/client using php and javascript

214PHP

Since Dec 8Pushed 11y ago1 watchersCompare

[ Source](https://github.com/jgswift/qtcp)[ Packagist](https://packagist.org/packages/jgswift/qtcp)[ RSS](/packages/jgswift-qtcp/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

qtcp
====

[](#qtcp)

Web socket client/server using php and javascript

[![Build Status](https://camo.githubusercontent.com/12d2c185ec2b8e2580fce7d766093fc377a97a55f05a06cd8e2d00e9cf821149/68747470733a2f2f7472617669732d63692e6f72672f6a6773776966742f717463702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jgswift/qtcp)

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

[](#installation)

Install via [composer](https://getcomposer.org/):

```
php composer.phar require jgswift/qtcp:dev-master
```

Dependency
----------

[](#dependency)

- [php](http://php.net) 5.5+
- [html5 web sockets](http://caniuse.com/#feat=websockets)
- [cboden/ratchet](http://github.com/cboden/ratchet)
- [symfony/console](http://github.com/symfony/console)
- [jgswift/qtil](http://github.com/jgswift/qtil)
- [jgswift/qio](http://github.com/jgswift/qio)
- [jgswift/observr](http://github.com/jgswift/observr)
- [jgswift/bubblr](http://github.com/jgswift/bubblr)

Description
-----------

[](#description)

qtcp is an experimental abstraction layer for client/server applications using websockets

Usage
-----

[](#usage)

```
$app = new qtcp\Network\Application(['0.0.0.0',8081]);

$app->attach('connect',function($client) {
    $client->attach('event', function($client, $e) {
        /* do something with event */
    });

    $client->attach('disconnect', function() {
        /* teardown client here */
    });
});

$app->run();
```

Examples
--------

[](#examples)

### Sample Stream

[](#sample-stream)

*[tests/Examples/SampleStream](http://github.com/jgswift/qtcp/tree/master/tests/Examples/SampleStream)*

The sample stream serves as a conceptual prototype to demonstrate the most basic functionality

#### Server

[](#server)

**Configure**

First, configure the host and port by editing the [config.js](http://github.com/jgswift/qtcp/tree/master/tests/Examples/SampleStream/config.js)

If you intend to run the client and server together on the same box, a likely configuration may be the following

```
var SampleStream = {
    host: 'localhost',
    port: 8081
};
```

**Run**

In terminal or via SSH, navigate to the directory qtcp is located in and start the server

```
$ cd vendor/jgswift/qtcp/
$ php tests/Examples/SampleStream/Server.php localhost:8081
```

The server will start and you will see

```
Starting server..
Server started.

```

**[Code](http://github.com/jgswift/qtcp/blob/master/tests/Examples/SampleStream/Server.php)**

```
$app = new qtcp\Network\Application([$host,$port]);

$app->attach('connect',function($client) {
    $client->attach('event', function($client, $e) {
        /* send reply */
        $client->send(new qtcp\Network\Packet('event',['hello world!']));
    });

    $client->attach('disconnect', function() {
        /* do something with disconnect */
    });
});

$app->run();
```

#### Client

[](#client)

Open a web browser and navigate to `http://localhost/your_project_directory/vendor/jgswift/qtcp/tests/Examples/SampleStream`.
*Note: Modify path if qtcp is in a different directory.*

A sample application will appear and click the button to send your first packet

**[Code](http://github.com/jgswift/qtcp/blob/master/tests/Examples/SampleStream/index.php)**

```
qtcp.network.client = new qtcp.client(
    "body",
    new qtcp.stream(
        new qtcp.resource(SampleStream.host,SampleStream.port)
    )
);

// attach packet processor for event packet
qtcp.network.client.attach("event",function(data) {
    $("#response").html(data[0]);
});

// connect to server
qtcp.network.client.connect();

// send event packet with some dummy data
$('input').on('click',function() {
    qtcp.network.client.send(new qtcp.network.packet("event"),{var1:"test"});
});
```

### Currency Stream

[](#currency-stream)

*[tests/Examples/CurrencyStream](http://github.com/jgswift/qtcp/tree/master/tests/Examples/CurrencyStream)*

The currency stream example simulates a currency index which concurrently updates all clients with price changes.

#### Server

[](#server-1)

**Configure**

Like above, configure the host and port by editing the [config.js](http://github.com/jgswift/qtcp/tree/master/tests/Examples/CurrencyStream/config.js)

If you intend to run the client and server together on the same box, a likely configuration may be the following

```
var CurrencyStream = {
    host: 'localhost',
    port: 8081
};
```

**Run**

In terminal or via SSH, navigate to the directory qtcp is located in and start the server

```
$ cd vendor/jgswift/qtcp/
$ php tests/Examples/CurrencyStream/Server.php
```

Alternatively, you may specify the host/port

```
$ php tests/Examples/CurrencyStream/Server.php 0.0.0.0:8081
```

The server will start and you will see

```
Starting server..
Server started.

```

#### Client

[](#client-1)

Open a web browser and navigate to `http://localhost/your_project_directory/vendor/jgswift/qtcp/tests/Examples/CurrencyStream`.
*Note: Modify path if qtcp is in a different directory.*

The price streaming application will list a currency index. Check any boxes on the left to initiate streaming.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

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/e60e96f18d8a9dc2aff1363eedbaf210acc96666e7497d2a83d5a416ef397295?d=identicon)[jgswift](/maintainers/jgswift)

---

Top Contributors

[![jgswift](https://avatars.githubusercontent.com/u/661738?v=4)](https://github.com/jgswift "jgswift (30 commits)")

### Embed Badge

![Health badge](/badges/jgswift-qtcp/health.svg)

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M315](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M291](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[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)
