You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
13
vendor/swoole/examples/event/cycle.php
vendored
Executable file
13
vendor/swoole/examples/event/cycle.php
vendored
Executable file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
Swoole\Timer::tick(2000, function ($id) {
|
||||
var_dump($id);
|
||||
});
|
||||
|
||||
Swoole\Event::cycle(function () {
|
||||
echo "hello [1]\n";
|
||||
Swoole\Event::cycle(function () {
|
||||
echo "hello [2]\n";
|
||||
Swoole\Event::cycle(null);
|
||||
});
|
||||
});
|
15
vendor/swoole/examples/event/inotify.php
vendored
Executable file
15
vendor/swoole/examples/event/inotify.php
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
//创建一个inotify句柄
|
||||
$fd = inotify_init();
|
||||
|
||||
//监听文件,仅监听修改操作,如果想要监听所有事件可以使用IN_ALL_EVENTS
|
||||
$watch_descriptor = inotify_add_watch($fd, __DIR__.'/inotify.data', IN_MODIFY);
|
||||
|
||||
swoole_event_add($fd, function ($fd) {
|
||||
$events = inotify_read($fd);
|
||||
if ($events) {
|
||||
foreach ($events as $event) {
|
||||
echo "inotify Event :" . var_export($event, 1) . "\n";
|
||||
}
|
||||
}
|
||||
});
|
53
vendor/swoole/examples/event/sockets.php
vendored
Executable file
53
vendor/swoole/examples/event/sockets.php
vendored
Executable file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* require ./configure --enable-sockets
|
||||
*/
|
||||
|
||||
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Unable to create socket\n");
|
||||
|
||||
socket_set_nonblock($socket) or die("Unable to set nonblock on socket\n");
|
||||
|
||||
function socket_onRead($socket)
|
||||
{
|
||||
static $i = 0;
|
||||
|
||||
echo socket_read($socket, 8192)."\n";
|
||||
$i ++;
|
||||
if ($i > 10)
|
||||
{
|
||||
echo "finish\n";
|
||||
swoole_event_del($socket);
|
||||
socket_close($socket);
|
||||
}
|
||||
else
|
||||
{
|
||||
sleep(1);
|
||||
swoole_event_set($socket, null, 'socket_onWrite', SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
function socket_onWrite($socket)
|
||||
{
|
||||
socket_write($socket, "hi swoole");
|
||||
swoole_event_set($socket, null, null, SWOOLE_EVENT_READ);
|
||||
}
|
||||
|
||||
function socket_onConnect($socket)
|
||||
{
|
||||
$err = socket_get_option($socket, SOL_SOCKET, SO_ERROR);
|
||||
if ($err == 0)
|
||||
{
|
||||
echo "connect server success\n";
|
||||
swoole_event_set($socket, null, 'socket_onWrite', SWOOLE_EVENT_READ);
|
||||
socket_write($socket, "first package\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "connect server failed\n";
|
||||
swoole_event_del($socket);
|
||||
socket_close($socket);
|
||||
}
|
||||
}
|
||||
|
||||
swoole_event_add($socket, 'socket_onRead', 'socket_onConnect', SWOOLE_EVENT_WRITE);
|
||||
@socket_connect($socket, '127.0.0.1', 9501);
|
4
vendor/swoole/examples/event/stdin.php
vendored
Executable file
4
vendor/swoole/examples/event/stdin.php
vendored
Executable file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
swoole_event_add(STDIN, function($fp) {
|
||||
echo "STDIN: ".fread($fp, 8192);
|
||||
});
|
21
vendor/swoole/examples/event/stream.php
vendored
Executable file
21
vendor/swoole/examples/event/stream.php
vendored
Executable file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
$fp = stream_socket_client("tcp://127.0.0.1:9502", $errno, $errstr, 30);
|
||||
if (!$fp) {
|
||||
exit("$errstr ($errno)<br />\n");
|
||||
}
|
||||
fwrite($fp, "HELLO world");
|
||||
|
||||
function stream_onRead($fp)
|
||||
{
|
||||
echo fread($fp, 1024)."\n";
|
||||
sleep(1);
|
||||
swoole_event_write($fp, "hello world");
|
||||
//swoole_event_set($fp, null, null, SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE);
|
||||
//swoole_event_del($fp);
|
||||
//fclose($fp);
|
||||
}
|
||||
|
||||
|
||||
swoole_event_add($fp, 'stream_onRead');
|
||||
|
||||
echo "start\n";
|
10
vendor/swoole/examples/event/test.php
vendored
Executable file
10
vendor/swoole/examples/event/test.php
vendored
Executable file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$fp = stream_socket_client("tcp://127.0.0.1:9501", $errno, $errstr, 30);
|
||||
fwrite($fp, "HELLO world");
|
||||
|
||||
swoole_event_add($fp, function ($fp) {
|
||||
echo fread($fp, 1024)."\n";
|
||||
swoole_event_del($fp);
|
||||
fclose($fp);
|
||||
});
|
||||
|
Reference in New Issue
Block a user