aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/react/event-loop/examples
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-16 21:09:05 +0200
committermarvin-borner@live.com2018-04-16 21:09:05 +0200
commitcf14306c2b3f82a81f8d56669a71633b4d4b5fce (patch)
tree86700651aa180026e89a66064b0364b1e4346f3f /assets/php/vendor/react/event-loop/examples
parent619b01b3615458c4ed78bfaeabb6b1a47cc8ad8b (diff)
Main merge to user management system - files are now at /main/public/
Diffstat (limited to 'assets/php/vendor/react/event-loop/examples')
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/01-timers.php15
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/02-periodic.php16
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/03-ticks.php15
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/04-signals.php19
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/11-consume-stdin.php30
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/12-generate-yes.php41
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/13-http-client-blocking.php35
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/14-http-client-async.php63
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/21-http-server.php36
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/91-benchmark-ticks.php15
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/92-benchmark-timers.php15
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/93-benchmark-ticks-delay.php22
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/94-benchmark-timers-delay.php22
-rwxr-xr-xassets/php/vendor/react/event-loop/examples/95-benchmark-memory.php67
14 files changed, 0 insertions, 411 deletions
diff --git a/assets/php/vendor/react/event-loop/examples/01-timers.php b/assets/php/vendor/react/event-loop/examples/01-timers.php
deleted file mode 100755
index e6107e4..0000000
--- a/assets/php/vendor/react/event-loop/examples/01-timers.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = React\EventLoop\Factory::create();
-
-$loop->addTimer(0.8, function () {
- echo 'world!' . PHP_EOL;
-});
-
-$loop->addTimer(0.3, function () {
- echo 'hello ';
-});
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/02-periodic.php b/assets/php/vendor/react/event-loop/examples/02-periodic.php
deleted file mode 100755
index 5e138a6..0000000
--- a/assets/php/vendor/react/event-loop/examples/02-periodic.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = React\EventLoop\Factory::create();
-
-$timer = $loop->addPeriodicTimer(0.1, function () {
- echo 'tick!' . PHP_EOL;
-});
-
-$loop->addTimer(1.0, function () use ($loop, $timer) {
- $loop->cancelTimer($timer);
- echo 'Done' . PHP_EOL;
-});
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/03-ticks.php b/assets/php/vendor/react/event-loop/examples/03-ticks.php
deleted file mode 100755
index 3f36c6d..0000000
--- a/assets/php/vendor/react/event-loop/examples/03-ticks.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = React\EventLoop\Factory::create();
-
-$loop->futureTick(function () {
- echo 'b';
-});
-$loop->futureTick(function () {
- echo 'c';
-});
-echo 'a';
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/04-signals.php b/assets/php/vendor/react/event-loop/examples/04-signals.php
deleted file mode 100755
index 90b6898..0000000
--- a/assets/php/vendor/react/event-loop/examples/04-signals.php
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-require __DIR__ . '/../vendor/autoload.php';
-
-if (!defined('SIGINT')) {
- fwrite(STDERR, 'Not supported on your platform (ext-pcntl missing or Windows?)' . PHP_EOL);
- exit(1);
-}
-
-$loop = React\EventLoop\Factory::create();
-
-$loop->addSignal(SIGINT, $func = function ($signal) use ($loop, &$func) {
- echo 'Signal: ', (string)$signal, PHP_EOL;
- $loop->removeSignal(SIGINT, $func);
-});
-
-echo 'Listening for SIGINT. Use "kill -SIGINT ' . getmypid() . '" or CTRL+C' . PHP_EOL;
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/11-consume-stdin.php b/assets/php/vendor/react/event-loop/examples/11-consume-stdin.php
deleted file mode 100755
index 2a77245..0000000
--- a/assets/php/vendor/react/event-loop/examples/11-consume-stdin.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-use React\EventLoop\Factory;
-
-require __DIR__ . '/../vendor/autoload.php';
-
-if (!defined('STDIN') || stream_set_blocking(STDIN, false) !== true) {
- fwrite(STDERR, 'ERROR: Unable to set STDIN non-blocking (not CLI or Windows?)' . PHP_EOL);
- exit(1);
-}
-
-$loop = Factory::create();
-
-// read everything from STDIN and report number of bytes
-// for illustration purposes only, should use react/stream instead
-$loop->addReadStream(STDIN, function ($stream) use ($loop) {
- $chunk = fread($stream, 64 * 1024);
-
- // reading nothing means we reached EOF
- if ($chunk === '') {
- $loop->removeReadStream($stream);
- stream_set_blocking($stream, true);
- fclose($stream);
- return;
- }
-
- echo strlen($chunk) . ' bytes' . PHP_EOL;
-});
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/12-generate-yes.php b/assets/php/vendor/react/event-loop/examples/12-generate-yes.php
deleted file mode 100755
index ebc2beb..0000000
--- a/assets/php/vendor/react/event-loop/examples/12-generate-yes.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-require __DIR__ . '/../vendor/autoload.php';
-
-// data can be given as first argument or defaults to "y"
-$data = (isset($argv[1]) ? $argv[1] : 'y') . "\n";
-
-// repeat data X times in order to fill around 200 KB
-$data = str_repeat($data, round(200000 / strlen($data)));
-
-$loop = React\EventLoop\Factory::create();
-
-if (!defined('STDOUT') || stream_set_blocking(STDOUT, false) !== true) {
- fwrite(STDERR, 'ERROR: Unable to set STDOUT non-blocking (not CLI or Windows?)' . PHP_EOL);
- exit(1);
-}
-
-// write data to STDOUT whenever its write buffer accepts data
-// for illustrations purpose only, should use react/stream instead
-$loop->addWriteStream(STDOUT, function ($stdout) use ($loop, &$data) {
- // try to write data
- $r = fwrite($stdout, $data);
-
- // nothing could be written despite being writable => closed
- if ($r === 0) {
- $loop->removeWriteStream($stdout);
- fclose($stdout);
- stream_set_blocking($stdout, true);
- fwrite(STDERR, 'Stopped because STDOUT closed' . PHP_EOL);
-
- return;
- }
-
- // implement a very simple ring buffer, unless everything has been written at once:
- // everything written in this iteration will be appended for next iteration
- if (isset($data[$r])) {
- $data = substr($data, $r) . substr($data, 0, $r);
- }
-});
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/13-http-client-blocking.php b/assets/php/vendor/react/event-loop/examples/13-http-client-blocking.php
deleted file mode 100755
index a2dde55..0000000
--- a/assets/php/vendor/react/event-loop/examples/13-http-client-blocking.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-
-use React\EventLoop\Factory;
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = Factory::create();
-
-// connect to www.google.com:80 (blocking call!)
-// for illustration purposes only, should use react/socket instead
-$stream = stream_socket_client('tcp://www.google.com:80');
-if (!$stream) {
- exit(1);
-}
-stream_set_blocking($stream, false);
-
-// send HTTP request
-fwrite($stream, "GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n");
-
-// wait for HTTP response
-$loop->addReadStream($stream, function ($stream) use ($loop) {
- $chunk = fread($stream, 64 * 1024);
-
- // reading nothing means we reached EOF
- if ($chunk === '') {
- echo '[END]' . PHP_EOL;
- $loop->removeReadStream($stream);
- fclose($stream);
- return;
- }
-
- echo $chunk;
-});
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/14-http-client-async.php b/assets/php/vendor/react/event-loop/examples/14-http-client-async.php
deleted file mode 100755
index c82c988..0000000
--- a/assets/php/vendor/react/event-loop/examples/14-http-client-async.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-use React\EventLoop\Factory;
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = Factory::create();
-
-// resolve hostname before establishing TCP/IP connection (resolving DNS is still blocking here)
-// for illustration purposes only, should use react/socket or react/dns instead!
-$ip = gethostbyname('www.google.com');
-if (ip2long($ip) === false) {
- echo 'Unable to resolve hostname' . PHP_EOL;
- exit(1);
-}
-
-// establish TCP/IP connection (non-blocking)
-// for illustraction purposes only, should use react/socket instead!
-$stream = stream_socket_client('tcp://' . $ip . ':80', $errno, $errstr, null, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
-if (!$stream) {
- exit(1);
-}
-stream_set_blocking($stream, false);
-
-// print progress every 10ms
-echo 'Connecting';
-$timer = $loop->addPeriodicTimer(0.01, function () {
- echo '.';
-});
-
-// wait for connection success/error
-$loop->addWriteStream($stream, function ($stream) use ($loop, $timer) {
- $loop->removeWriteStream($stream);
- $loop->cancelTimer($timer);
-
- // check for socket error (connection rejected)
- if (stream_socket_get_name($stream, true) === false) {
- echo '[unable to connect]' . PHP_EOL;
- exit(1);
- } else {
- echo '[connected]' . PHP_EOL;
- }
-
- // send HTTP request
- fwrite($stream, "GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n");
-
- // wait for HTTP response
- $loop->addReadStream($stream, function ($stream) use ($loop) {
- $chunk = fread($stream, 64 * 1024);
-
- // reading nothing means we reached EOF
- if ($chunk === '') {
- echo '[END]' . PHP_EOL;
- $loop->removeReadStream($stream);
- fclose($stream);
- return;
- }
-
- echo $chunk;
- });
-});
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/21-http-server.php b/assets/php/vendor/react/event-loop/examples/21-http-server.php
deleted file mode 100755
index 89520ce..0000000
--- a/assets/php/vendor/react/event-loop/examples/21-http-server.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = React\EventLoop\Factory::create();
-
-// start TCP/IP server on localhost:8080
-// for illustration purposes only, should use react/socket instead
-$server = stream_socket_server('tcp://127.0.0.1:8080');
-if (!$server) {
- exit(1);
-}
-stream_set_blocking($server, false);
-
-// wait for incoming connections on server socket
-$loop->addReadStream($server, function ($server) use ($loop) {
- $conn = stream_socket_accept($server);
- $data = "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nHi\n";
- $loop->addWriteStream($conn, function ($conn) use (&$data, $loop) {
- $written = fwrite($conn, $data);
- if ($written === strlen($data)) {
- fclose($conn);
- $loop->removeWriteStream($conn);
- } else {
- $data = substr($data, $written);
- }
- });
-});
-
-$loop->addPeriodicTimer(5, function () {
- $memory = memory_get_usage() / 1024;
- $formatted = number_format($memory, 3).'K';
- echo "Current memory usage: {$formatted}\n";
-});
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/91-benchmark-ticks.php b/assets/php/vendor/react/event-loop/examples/91-benchmark-ticks.php
deleted file mode 100755
index 3f4690b..0000000
--- a/assets/php/vendor/react/event-loop/examples/91-benchmark-ticks.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-use React\EventLoop\Factory;
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = Factory::create();
-
-$n = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
-
-for ($i = 0; $i < $n; ++$i) {
- $loop->futureTick(function () { });
-}
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/92-benchmark-timers.php b/assets/php/vendor/react/event-loop/examples/92-benchmark-timers.php
deleted file mode 100755
index e2e02e4..0000000
--- a/assets/php/vendor/react/event-loop/examples/92-benchmark-timers.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-use React\EventLoop\Factory;
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = Factory::create();
-
-$n = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
-
-for ($i = 0; $i < $n; ++$i) {
- $loop->addTimer(0, function () { });
-}
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/93-benchmark-ticks-delay.php b/assets/php/vendor/react/event-loop/examples/93-benchmark-ticks-delay.php
deleted file mode 100755
index 95ee78c..0000000
--- a/assets/php/vendor/react/event-loop/examples/93-benchmark-ticks-delay.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-use React\EventLoop\Factory;
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = Factory::create();
-
-$ticks = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
-$tick = function () use (&$tick, &$ticks, $loop) {
- if ($ticks > 0) {
- --$ticks;
- //$loop->addTimer(0, $tick);
- $loop->futureTick($tick);
- } else {
- echo 'done';
- }
-};
-
-$tick();
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/94-benchmark-timers-delay.php b/assets/php/vendor/react/event-loop/examples/94-benchmark-timers-delay.php
deleted file mode 100755
index 2d6cfa2..0000000
--- a/assets/php/vendor/react/event-loop/examples/94-benchmark-timers-delay.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-use React\EventLoop\Factory;
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$loop = Factory::create();
-
-$ticks = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
-$tick = function () use (&$tick, &$ticks, $loop) {
- if ($ticks > 0) {
- --$ticks;
- //$loop->futureTick($tick);
- $loop->addTimer(0, $tick);
- } else {
- echo 'done';
- }
-};
-
-$tick();
-
-$loop->run();
diff --git a/assets/php/vendor/react/event-loop/examples/95-benchmark-memory.php b/assets/php/vendor/react/event-loop/examples/95-benchmark-memory.php
deleted file mode 100755
index 084c404..0000000
--- a/assets/php/vendor/react/event-loop/examples/95-benchmark-memory.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-/**
- * Run the script indefinitely seconds with the loop from the factory and report every 2 seconds:
- * php 95-benchmark-memory.php
- * Run the script for 30 seconds with the stream_select loop and report every 10 seconds:
- * php 95-benchmark-memory.php -t 30 -l StreamSelect -r 10
- */
-
-use React\EventLoop\Factory;
-use React\EventLoop\LoopInterface;
-use React\EventLoop\TimerInterface;
-
-require __DIR__ . '/../vendor/autoload.php';
-
-$args = getopt('t:l:r:');
-$t = isset($args['t']) ? (int)$args['t'] : 0;
-$loop = isset($args['l']) && class_exists('React\EventLoop\\' . $args['l'] . 'Loop') ? 'React\EventLoop\\' . $args['l'] . 'Loop' : Factory::create();
-
-if (!($loop instanceof LoopInterface)) {
- $loop = new $loop();
-}
-
-$r = isset($args['r']) ? (int)$args['r'] : 2;
-
-$runs = 0;
-
-if (5 < $t) {
- $loop->addTimer($t, function () use ($loop) {
- $loop->stop();
- });
-
-}
-
-$loop->addPeriodicTimer(0.001, function () use (&$runs, $loop) {
- $runs++;
-
- $loop->addPeriodicTimer(1, function (TimerInterface $timer) use ($loop) {
- $loop->cancelTimer($timer);
- });
-});
-
-$loop->addPeriodicTimer($r, function () use (&$runs) {
- $kmem = round(memory_get_usage() / 1024);
- $kmemReal = round(memory_get_usage(true) / 1024);
- echo "Runs:\t\t\t$runs\n";
- echo "Memory (internal):\t$kmem KiB\n";
- echo "Memory (real):\t\t$kmemReal KiB\n";
- echo str_repeat('-', 50), "\n";
-});
-
-echo "PHP Version:\t\t", phpversion(), "\n";
-echo "Loop\t\t\t", get_class($loop), "\n";
-echo "Time\t\t\t", date('r'), "\n";
-
-echo str_repeat('-', 50), "\n";
-
-$beginTime = time();
-$loop->run();
-$endTime = time();
-$timeTaken = $endTime - $beginTime;
-
-echo "PHP Version:\t\t", phpversion(), "\n";
-echo "Loop\t\t\t", get_class($loop), "\n";
-echo "Time\t\t\t", date('r'), "\n";
-echo "Time taken\t\t", $timeTaken, " seconds\n";
-echo "Runs per second\t\t", round($runs / $timeTaken), "\n";