aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/react/stream/examples/02-https.php
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-10 21:50:16 +0200
committermarvin-borner@live.com2018-04-10 21:54:48 +0200
commitfc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch)
treeb0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/react/stream/examples/02-https.php
parent286d643180672f20526f3dc3bd19d7b751e2fa97 (diff)
Initial Commit
Diffstat (limited to 'assets/php/vendor/react/stream/examples/02-https.php')
-rw-r--r--assets/php/vendor/react/stream/examples/02-https.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/assets/php/vendor/react/stream/examples/02-https.php b/assets/php/vendor/react/stream/examples/02-https.php
new file mode 100644
index 0000000..163f7c8
--- /dev/null
+++ b/assets/php/vendor/react/stream/examples/02-https.php
@@ -0,0 +1,40 @@
+<?php
+
+// Simple secure HTTPS client example (for illustration purposes only).
+// This shows how a secure TLS connection is established to then send an
+// application level protocol message (HTTP).
+// Real applications should use react/http-client instead!
+//
+// This simple example only accepts an optional host parameter to send the
+// request to.
+//
+// $ php examples/02-https.php
+// $ php examples/02-https.php reactphp.org
+
+use React\EventLoop\Factory;
+use React\Stream\DuplexResourceStream;
+
+require __DIR__ . '/../vendor/autoload.php';
+
+$host = isset($argv[1]) ? $argv[1] : 'www.google.com';
+
+// connect to tls://www.google.com:443 (blocking call!)
+// for illustration purposes only, should use react/http-client or react/socket instead!
+$resource = stream_socket_client('tls://' . $host . ':443');
+if (!$resource) {
+ exit(1);
+}
+
+$loop = Factory::create();
+$stream = new DuplexResourceStream($resource, $loop);
+
+$stream->on('data', function ($chunk) {
+ echo $chunk;
+});
+$stream->on('close', function () {
+ echo '[CLOSED]' . PHP_EOL;
+});
+
+$stream->write("GET / HTTP/1.0\r\nHost: $host\r\n\r\n");
+
+$loop->run();