Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build your own webserver with PHP

Igor Wiedler
November 20, 2013

Build your own webserver with PHP

Igor Wiedler

November 20, 2013
Tweet

More Decks by Igor Wiedler

Other Decks in Programming

Transcript

  1. SYN

  2. ACK

  3. Layers +---+--------------+----------------+ | 7 | Application | HTTP, FTP, DNS

    | | 6 | Presentation | TLS | | 5 | Session | TCP | | 4 | Transport | TCP, UDP | | 3 | Network | IP | | 2 | Data Link | ARP, PPP | | 1 | Physical | | +---+--------------+----------------+
  4. Request GET / HTTP/1.1 <--- request line Host: igor.io <---

    header <--- line feed <--- body (blank)
  5. • 1xx - Special protocol stuff • 2xx - All

    good • 3xx - Redirection • 4xx - You messed up • 5xx - I messed up Status codes
  6. Request GET / HTTP/1.1 <--- request line Host: igor.io <---

    header <--- line feed <--- body (blank)
  7. Problem? • Incomplete HTTP parser • Missing error handling •

    Assumption: request can be read in one go • Assumption: request no larger than 512 bytes • Assumption: request/response body fits in memory • Blocking I/O
  8. Bonus • Memory leaks • Too fast reads / too

    slow writes • libevent / libev / libuv • Promises • Generators • pthreads • WebSockets