3. SymfonyCafe Kyiv 2015
About myself
Main tools: C++, PHP, Linux
Preferred area: troubleshooting, optimizations,
proof-of-concept, tech leading
Opensource: Drupal
3
4. SymfonyCafe Kyiv 2015
Task: check of sitemap.xml
- Rapid check of large sitemap.xml
- Check both local and remote sitemap
- learn something new
- candidates: PHP, C++, Bash, ReactPHP, Go,
Rust, ...
4
5. SymfonyCafe Kyiv 2015
- Reactor pattern
- Event Driven
- Non-blocking I/O
- Pure PHP, small
5
What is ReactPHP?
6. SymfonyCafe Kyiv 2015
Projects based on ReactPHP
- Redis Client/Server
- Asterisk Management
- Munin
- Async SQL client
- … several more
6
9. SymfonyCafe Kyiv 2015
Layers
- Event loop as a backbone
- Low-level components: DNS resolver,
timers/ticks, sockets, network client/server)
- Middle level: HTTP Server/Clients
- High: Promise, Stream
9
10. SymfonyCafe Kyiv 2015
Layers in practice
10
$loop = ReactEventLoopFactory::create();
$socket = new ReactSocketServer($loop);
$http = new ReactHttpServer($socket);
Higher
14. SymfonyCafe Kyiv 2015
More: Promises
Proxy objects to store values for yet unknown
results
Also known as Deferred, Yield and Futures in
other languages
14
15. SymfonyCafe Kyiv 2015
- https://github.com/reactphp/react/wiki/Users :
about 40 projects;
- Can be evaluated as alternative when you need to
create multithreaded app
- Community
- Unit tests
15
Project state
18. SymfonyCafe Kyiv 2015
The Octopus project
An app which uses two features
of the ReactPHP:
- Async Http Requests;
- Timers.
Purpose: education + simple tool needed to
check sitemap validity
18
19. SymfonyCafe Kyiv 2015
Parallel execution of GET requests
19
❖ ~70 ms per page vs ~300 ms for sequential check;
❖ low memory and CPU usage
23. SymfonyCafe Kyiv 2015
- a few full days of development, initially with idea of
rapid check of sitemap.xml before Google;
- about 12k of PHP code;
- 1 accepted PR to ReactPHP;
- works faster than script with sequential checking (6x);
- application core was developed relatively easy;
Octopus facts and numbers
23