From f184905e4ec0d29dc679c15de4cfcdb45db91048 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 cb027228..99b72eb7 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. @@ -39,33 +40,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(); + +$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->addPeriodicTimer(5, function () { - $memory = memory_get_usage() / 1024; - $formatted = number_format($memory, 3).'K'; - echo "Current memory usage: {$formatted}\n"; - }); +$loop->addPeriodicTimer(5, function () { + $memory = memory_get_usage() / 1024; + $formatted = number_format($memory, 3).'K'; + echo "Current memory usage: {$formatted}\n"; +}); - $loop->run(); +$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 025cd88cb5c2031420f16688fa5b1f96c59b7b6e 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 99b72eb7..ab1f462f 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