SkillAgentSearch skills...

Skyray

A Promise based networking library for PHP written in C

Install / Use

/learn @SkyrayLabs/Skyray
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Skyray - A networking library for PHP written in C

Skyray provides non-blocking I/O and multi-processing facilities for PHP, it is intended be to as flexible as possible to suit for various applications.

Features

  • Well designed OO interfaces for I/O and Process management
  • Stream oriented abstraction, everything is stream, simple and clean
  • Build servers with PHP, quick and easy
  • Support both non-blocking and blocking interfaces
  • Support millisecond timer (both periodic and non-periodic)
  • Bring all possibilities to PHP world ...

Installation

git clone https://github.com/SkyrayLabs/Skyray.git --recursive
phpize
./configure --with-php-config=/path/to/php-config
make & make install

NOTES : Skyray requires PHP7, please be sure your have php7 installed before building.

Examples

A Simple Echo Server

server.php

use skyray\Reactor;
use skyray\stream\Server;
use skyray\stream\ProtocolInterface;

class SimpleEchoProtocol implements ProtocolInterface
{
    protected $debug;
    protected $stream;

    public function __construct($debug = false)
    {
        $this->debug = $debug;
    }

    public function log($info)
    {
        echo '[server]: ' . $info . PHP_EOL;
    }

    public function connectStream($stream)
    {
        $this->stream = $stream;
    }

    public function streamConnected()
    {
        $this->debug && $this->log('connected');
    }

    public function dataReceived($data)
    {
        $this->log('received data: ' . $data);
        $this->stream->write($data);
    }

    public function streamClosed()
    {
        $this->debug && $this->log('closed');
    }
}


$reactor = new Reactor();

$server = new Server(function () {
    return new SimpleEchoProtocol(true);
}, $reactor);

$server->listen('0.0.0.0', 10000);

$reactor->run();

client.php

use skyray\stream\Client;

$client = new Client();
$stream = $client->connectTCP('127.0.0.1', 10000);
$stream->write('hello world');
var_dump($stream->read());
$stream->close();

Documentation

Documentation is not yet available, please refer here for prototype of all classes.

Participating

Skyray is still in active development, your participating is very wellcome!

You may participate in the following ways:

Related Skills

View on GitHub
GitHub Stars18
CategoryDevelopment
Updated5y ago
Forks0

Languages

C

Security Score

60/100

Audited on Sep 19, 2020

No findings