forked from reactphp/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-hello-world-https.php
More file actions
34 lines (26 loc) · 1010 Bytes
/
Copy path11-hello-world-https.php
File metadata and controls
34 lines (26 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Factory;
use React\Http\Response;
use React\Http\Server;
require __DIR__ . '/../vendor/autoload.php';
$loop = Factory::create();
$server = new Server(function (ServerRequestInterface $request) {
return new Response(
200,
array(
'Content-Type' => 'text/plain'
),
"Hello world!\n"
);
});
$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0', $loop);
$socket = new \React\Socket\SecureServer($socket, $loop, array(
'local_cert' => isset($argv[2]) ? $argv[2] : __DIR__ . '/localhost.pem',
'verify_peer' => false, // Used to authenticate the identity of the remote peer (client)
'verify_peer_name' => false // Used to authenticate the identity of the remote peer (client)
));
$server->listen($socket);
//$socket->on('error', 'printf');
echo 'Listening on ' . str_replace('tls:', 'https:', $socket->getAddress()) . PHP_EOL;
$loop->run();