Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
47 lines (37 loc) · 1.26 KB

File metadata and controls

47 lines (37 loc) · 1.26 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
45
46
47
<?php
declare(strict_types=1);
use Revolt\EventLoop;
require __DIR__ . '/../vendor/autoload.php';
// start TCP/IP server on localhost:8080
// for illustration purposes only, should use socket abstracting instead
$server = \stream_socket_server('tcp://0.0.0.0:8080');
if (!$server) {
exit(1);
}
\stream_set_blocking($server, false);
echo "Visit http://localhost:8080/ in your browser." . PHP_EOL;
// wait for incoming connections on server socket
EventLoop::onReadable($server, function ($watcher, $server) {
$conn = \stream_socket_accept($server);
if ($conn === false) {
echo "Error accepting connection\n";
exit(1);
}
$data = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 3\r\n\r\nHi\n";
EventLoop::onWritable($conn, function ($watcher, $conn) use (&$data) {
$written = \fwrite($conn, $data);
\assert($written !== false);
if ($written === \strlen($data)) {
\fclose($conn);
EventLoop::cancel($watcher);
} else {
$data = \substr($data, $written);
}
});
});
EventLoop::repeat(5, function () {
$memory = \memory_get_usage() / 1024;
$formatted = \number_format($memory).' KiB';
echo "Current memory usage: {$formatted}\n";
});
EventLoop::run();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.