From 820875a3cedadd6082aad5ed32d3758726b26143 Mon Sep 17 00:00:00 2001 From: Jan Sorgalla Date: Sat, 25 Mar 2017 12:57:14 +0100 Subject: [PATCH 1/2] Fix code indention and add some linebreaks --- README.md | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index d6f7da51..307e9a0e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # EventLoop Component -[![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) +[![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) Event loop abstraction layer that libraries can use for evented I/O. @@ -35,33 +36,35 @@ All of the loops support these features: ## Usage Here is an async HTTP server built with just the event loop. + ```php - $loop = React\EventLoop\Factory::create(); - - $server = stream_socket_server('tcp://127.0.0.1:8080'); - stream_set_blocking($server, 0); - $loop->addReadStream($server, function ($server) use ($loop) { - $conn = stream_socket_accept($server); - $data = "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nHi\n"; - $loop->addWriteStream($conn, function ($conn) use (&$data, $loop) { - $written = fwrite($conn, $data); - if ($written === strlen($data)) { - fclose($conn); - $loop->removeStream($conn); - } else { - $data = substr($data, $written); - } - }); - }); +$loop = React\EventLoop\Factory::create(); - $loop->addPeriodicTimer(5, function () { - $memory = memory_get_usage() / 1024; - $formatted = number_format($memory, 3).'K'; - echo "Current memory usage: {$formatted}\n"; +$server = stream_socket_server('tcp://127.0.0.1:8080'); +stream_set_blocking($server, 0); +$loop->addReadStream($server, function ($server) use ($loop) { + $conn = stream_socket_accept($server); + $data = "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nHi\n"; + $loop->addWriteStream($conn, function ($conn) use (&$data, $loop) { + $written = fwrite($conn, $data); + if ($written === strlen($data)) { + fclose($conn); + $loop->removeStream($conn); + } else { + $data = substr($data, $written); + } }); +}); - $loop->run(); +$loop->addPeriodicTimer(5, function () { + $memory = memory_get_usage() / 1024; + $formatted = number_format($memory, 3).'K'; + echo "Current memory usage: {$formatted}\n"; +}); + +$loop->run(); ``` + **Note:** The factory is just for convenience. It tries to pick the best available implementation. Libraries `SHOULD` allow the user to inject an instance of the loop. They `MAY` use the factory when the user did not supply From 6e821cb612e24e82547a044d68ef9da2804f739a Mon Sep 17 00:00:00 2001 From: Jan Sorgalla Date: Sat, 25 Mar 2017 12:58:58 +0100 Subject: [PATCH 2/2] Use svg travis badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 307e9a0e..445640df 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # EventLoop Component -[![Build Status](https://secure.travis-ci.org/reactphp/event-loop.png?branch=master)](http://travis-ci.org/reactphp/event-loop) +[![Build Status](https://travis-ci.org/reactphp/event-loop.svg?branch=master)](https://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) Event loop abstraction layer that libraries can use for evented I/O. 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