Giter Site home page Giter Site logo

swoole's Introduction

Swoole

PHP's asynchronous & concurrent & distributed networking framework.

  • Event-driven
  • Full asynchronous non-blocking
  • Multi-Thread or Multi-Process
  • Millisecond timer
  • Asynchronous MySQL
  • AsyncTask workers

Example

Server

$serv = new swoole_server("127.0.0.1", 9501);
$serv->on('connect', function ($serv, $fd){
 	echo "Client:Connect.\n";
});
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
	$serv->send($fd, 'Swoole: '.$data);
    $serv->close($fd);
});
$serv->on('close', function ($serv, $fd) {
 	echo "Client: Close.\n";
});
$serv->start();

Client

$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);

$client->on("connect", function($cli) {
    $cli->send("hello world\n");
});

$client->on("receive", function($cli){
    $data = $cli->recv();
    echo "Receive: $data\n";
});

$client->on("error", function($cli){
    echo "connect fail\n";
});

$client->on("close", function($cli){
    echo "close\n";
    $cli->close();
});

$client->connect('127.0.0.1', 9501, 0.5);

Event

$fp = stream_socket_client("tcp://127.0.0.1:9501", $errno, $errstr, 30);
if (!$fp) {
    exit("$errstr ($errno)\n");
}
fwrite($fp, "HELLO world");
swoole_event_add($fp, function($fp){
	echo fgets($fp, 1024);
	swoole_event_del($fp);
    fclose($fp);
});

Files

Developer Mail-List

For PHP

cd swoole/
phpize
./configure
make && make install

For C/C++

cd swoole/
cmake .
make && make install

PHP Application Server

https://github.com/matyhtf/swoole_framework

Document

License

Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.html

swoole's People

Contributors

matyhtf avatar taobao-php avatar remicollet avatar recoye avatar shenzhe avatar betashepherd avatar

Watchers

LeoLuo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.