PHP & C asynchronous, concurrent and distributed framework.
Pull request Compare This branch is 3109 commits behind swoole:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
include
src
.gitignore
CREDITS
LICENSE
README.md
config.m4
main.c
php_swoole.h
swoole.c
swoole.php

README.md

php_swoole

PHP extension.A socket server framework.

feature

  • event driver. callback php function.
  • asynchronous and non-blocking.
  • no lock. no thread mutex. no semaphore.
  • separate read and write.
  • it can run at multi thread or multi proccess.

example

$serv = swoole_server_create("127.0.0.1", 9500, 1);
swoole_server_set($serv, array(
    'timeout'=>2.5,
    'poll_thread_num'=>1,
    'writer_num'=>2,
    'worker_num'=>2,
    'backlog'=>128,
    'max_request' => 1000, //worker process max request times
));
function my_onStart($serv)
{
    echo "Server:start\n";
}

function my_onShutdown($serv)
{
    echo "Server:onShutdown(\n";
}

function my_onClose($serv,$fd,$from_id)
{
  echo "Client:Close. fd=$fd|from_id=$from_id\n";
}

function my_onConnect($serv,$fd,$from_id)
{
    echo "Client:Connect. fd=$fd|from_id=$from_id\n";
}

function my_onReceive($serv,$fd,$from_id,$data)
{
    echo "Client:Data. fd=$fd|from_id=$from_id|data=$data\n";
    swoole_server_send($serv, $fd, "Server:$data");
}

swoole_server_handler($serv, 'onStart', 'my_onStart');
swoole_server_handler($serv, 'onConnect', 'my_onConnect');
swoole_server_handler($serv, 'onReceive', 'my_onReceive');
swoole_server_handler($serv, 'onClose', 'my_onClose');
swoole_server_handler($serv, 'onShutdown', 'my_onShutdown');

swoole_server_start($serv);
?>
php server.php

telnet 127.0.0.1 9500
hello
server: hello