Skip to content

Commit f184905

Browse files
committed
Fix code indention and add some linebreaks
1 parent 204ed4f commit f184905

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://secure.travis-ci.org/reactphp/event-loop.png?branch=master)](http://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

@@ -39,33 +40,35 @@ All of the loops support these features:
3940
## Usage
4041

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

61-
$loop->addPeriodicTimer(5, function () {
62-
$memory = memory_get_usage() / 1024;
63-
$formatted = number_format($memory, 3).'K';
64-
echo "Current memory usage: {$formatted}\n";
65-
});
63+
$loop->addPeriodicTimer(5, function () {
64+
$memory = memory_get_usage() / 1024;
65+
$formatted = number_format($memory, 3).'K';
66+
echo "Current memory usage: {$formatted}\n";
67+
});
6668

67-
$loop->run();
69+
$loop->run();
6870
```
71+
6972
**Note:** The factory is just for convenience. It tries to pick the best
7073
available implementation. Libraries `SHOULD` allow the user to inject an
7174
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