-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathtcp-ssl-server.php
More file actions
44 lines (36 loc) · 925 Bytes
/
tcp-ssl-server.php
File metadata and controls
44 lines (36 loc) · 925 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
35
36
37
38
39
40
41
42
43
44
<?php
require_once __DIR__.'/../Semaphore.php';
$context = stream_context_create([
'ssl' => [
'local_cert' => __DIR__.'/ssl/server-and-key.pem',
],
]);
$socketServer = stream_socket_server('tcp://127.0.0.1:19999', $errNo, $errStr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);
stream_socket_enable_crypto($socketServer, false);
$client = stream_socket_accept($socketServer);
stream_set_blocking($client, true);
if (@stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_TLSv1_2_SERVER)) {
fwrite($client, str_replace(
"\n",
"\r\n",
<<<EOR
HTTP/1.1 200 OK
Content-Type: text/plain
Test
EOR
));
} else {
fwrite($client, str_replace(
"\n",
"\r\n",
<<<EOR
HTTP/1.1 400 Bad Request
Content-Type: text/plain
Test
EOR
));
}
while (!@feof($client)) {
@fread($client, 1000);
}
Http\Client\Socket\Tests\Semaphore::release();