Skip to content

Commit ae8fe72

Browse files
authored
Merge pull request #89 from jsor-labs/0.4-add-pr85
Readme cleanup
2 parents 1d1773b + 6e821cb commit ae8fe72

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

README.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# EventLoop Component
22

3-
[![Build Status](https://secure.travis-ci.org/reactphp/event-loop.png?branch=master)](http://travis-ci.org/reactphp/event-loop) [![Code Climate](https://codeclimate.com/github/reactphp/event-loop/badges/gpa.svg)](https://codeclimate.com/github/reactphp/event-loop)
3+
[![Build Status](https://travis-ci.org/reactphp/event-loop.svg?branch=master)](https://travis-ci.org/reactphp/event-loop)
4+
[![Code Climate](https://codeclimate.com/github/reactphp/event-loop/badges/gpa.svg)](https://codeclimate.com/github/reactphp/event-loop)
45

56
Event loop abstraction layer that libraries can use for evented I/O.
67

@@ -35,33 +36,35 @@ All of the loops support these features:
3536
## Usage
3637

3738
Here is an async HTTP server built with just the event loop.
39+
3840
```php
39-
$loop = React\EventLoop\Factory::create();
40-
41-
$server = stream_socket_server('tcp://127.0.0.1:8080');
42-
stream_set_blocking($server, 0);
43-
$loop->addReadStream($server, function ($server) use ($loop) {
44-
$conn = stream_socket_accept($server);
45-
$data = "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nHi\n";
46-
$loop->addWriteStream($conn, function ($conn) use (&$data, $loop) {
47-
$written = fwrite($conn, $data);
48-
if ($written === strlen($data)) {
49-
fclose($conn);
50-
$loop->removeStream($conn);
51-
} else {
52-
$data = substr($data, $written);
53-
}
54-
});
55-
});
41+
$loop = React\EventLoop\Factory::create();
5642

57-
$loop->addPeriodicTimer(5, function () {
58-
$memory = memory_get_usage() / 1024;
59-
$formatted = number_format($memory, 3).'K';
60-
echo "Current memory usage: {$formatted}\n";
43+
$server = stream_socket_server('tcp://127.0.0.1:8080');
44+
stream_set_blocking($server, 0);
45+
$loop->addReadStream($server, function ($server) use ($loop) {
46+
$conn = stream_socket_accept($server);
47+
$data = "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nHi\n";
48+
$loop->addWriteStream($conn, function ($conn) use (&$data, $loop) {
49+
$written = fwrite($conn, $data);
50+
if ($written === strlen($data)) {
51+
fclose($conn);
52+
$loop->removeStream($conn);
53+
} else {
54+
$data = substr($data, $written);
55+
}
6156
});
57+
});
6258

63-
$loop->run();
59+
$loop->addPeriodicTimer(5, function () {
60+
$memory = memory_get_usage() / 1024;
61+
$formatted = number_format($memory, 3).'K';
62+
echo "Current memory usage: {$formatted}\n";
63+
});
64+
65+
$loop->run();
6466
```
67+
6568
**Note:** The factory is just for convenience. It tries to pick the best
6669
available implementation. Libraries `SHOULD` allow the user to inject an
6770
instance of the loop. They `MAY` use the factory when the user did not supply

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy