You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
28
vendor/swoole/examples/unixsock/async_client.php
vendored
Executable file
28
vendor/swoole/examples/unixsock/async_client.php
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
$client = new swoole_client(SWOOLE_SOCK_UNIX_STREAM, SWOOLE_SOCK_ASYNC);
|
||||
|
||||
$client->on("connect", function (swoole_client $cli)
|
||||
{
|
||||
$cli->send("GET / HTTP/1.1\r\n\r\n");
|
||||
});
|
||||
|
||||
$client->on("receive", function (swoole_client $cli, $data)
|
||||
{
|
||||
echo "Receive: $data";
|
||||
$cli->send(str_repeat('A', 100) . "\n");
|
||||
});
|
||||
|
||||
$client->on("error", function (swoole_client $cli)
|
||||
{
|
||||
echo "error: [" . $cli->errCode . "] " . socket_strerror($cli->errCode) . "\n";
|
||||
});
|
||||
|
||||
$client->on("close", function (swoole_client $cli)
|
||||
{
|
||||
echo "Connection close\n";
|
||||
});
|
||||
|
||||
$client->connect(__DIR__ . '/svr.sock', 0, -1);
|
||||
|
||||
swoole_event_wait();
|
||||
echo "exit\n";
|
12
vendor/swoole/examples/unixsock/dgram_client.php
vendored
Executable file
12
vendor/swoole/examples/unixsock/dgram_client.php
vendored
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$client = new swoole_client(SWOOLE_SOCK_UNIX_DGRAM, SWOOLE_SOCK_SYNC);
|
||||
if (!$client->connect(__DIR__ . '/svr.sock', 0, -1))
|
||||
{
|
||||
exit("connect failed. Error: {$client->errCode}\n");
|
||||
}
|
||||
|
||||
$client->send("hello world\n");
|
||||
echo $client->recv();
|
||||
$client->close();
|
||||
|
||||
sleep(1);
|
20
vendor/swoole/examples/unixsock/dgram_server.php
vendored
Executable file
20
vendor/swoole/examples/unixsock/dgram_server.php
vendored
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
$serv = new swoole_server(__DIR__."/svr.sock", 9501, SWOOLE_PROCESS, SWOOLE_UNIX_DGRAM);
|
||||
$serv->set(array(
|
||||
//'tcp_defer_accept' => 5,
|
||||
'worker_num' => 1,
|
||||
//'daemonize' => true,
|
||||
//'log_file' => '/tmp/swoole.log'
|
||||
));
|
||||
//$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
|
||||
// echo "[#".posix_getpid()."]\tClient[$fd]: $data\n";
|
||||
// $serv->send($fd, json_encode(array("hello" => $data, "from" => $from_id)).PHP_EOL);
|
||||
//});
|
||||
|
||||
$serv->on('Packet', function (swoole_server $serv, $data, $addr) {
|
||||
//echo "[#".posix_getpid()."]\tClient[{$addr['address']}]: $data\n";
|
||||
var_dump($addr);
|
||||
$serv->send($addr['address'], json_encode(array("hello" => $data, "addr" => $addr)).PHP_EOL);
|
||||
});
|
||||
|
||||
$serv->start();
|
12
vendor/swoole/examples/unixsock/stream_client.php
vendored
Executable file
12
vendor/swoole/examples/unixsock/stream_client.php
vendored
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$client = new swoole_client(SWOOLE_SOCK_UNIX_STREAM, SWOOLE_SOCK_SYNC);
|
||||
if (!$client->connect(__DIR__.'/svr.sock', 0, -1))
|
||||
{
|
||||
exit("connect failed. Error: {$client->errCode}\n");
|
||||
}
|
||||
|
||||
$client->send("hello world\n");
|
||||
echo $client->recv();
|
||||
$client->close();
|
||||
|
||||
sleep(1);
|
28
vendor/swoole/examples/unixsock/stream_server.php
vendored
Executable file
28
vendor/swoole/examples/unixsock/stream_server.php
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
$serv = new swoole_server(__DIR__."/svr.sock", 9501, SWOOLE_BASE, SWOOLE_SOCK_UNIX_STREAM);
|
||||
$serv->set(array(
|
||||
//'tcp_defer_accept' => 5,
|
||||
'worker_num' => 1,
|
||||
//'daemonize' => true,
|
||||
//'log_file' => '/tmp/swoole.log'
|
||||
));
|
||||
|
||||
$serv->on('start', function($serv){
|
||||
chmod($serv->host, 0777);
|
||||
});
|
||||
|
||||
$serv->on('Connect', function($serv, $fd, $reactorId) {
|
||||
echo "Connect, client={$fd}\n";
|
||||
});
|
||||
|
||||
$serv->on('Close', function($serv, $fd, $reactorId) {
|
||||
echo "Close, client={$fd}\n";
|
||||
});
|
||||
|
||||
$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data)
|
||||
{
|
||||
echo "[#" . posix_getpid() . "]\tClient[$fd]: $data\n";
|
||||
$serv->send($fd, json_encode(array("hello" => $data, "from" => $from_id)) . PHP_EOL);
|
||||
});
|
||||
|
||||
$serv->start();
|
Reference in New Issue
Block a user