Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The HttpKernelInterface is a lie (forumphp)
Search
Igor Wiedler
November 21, 2013
Programming
1.2k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The HttpKernelInterface is a lie (forumphp)
Igor Wiedler
November 21, 2013
More Decks by Igor Wiedler
See All by Igor Wiedler
Redis Bedtime Stories
igorw
1
360
Wide Event Analytics (LISA19)
igorw
4
940
a day in the life of a request
igorw
0
170
production: an owner's manual
igorw
0
190
The Power of 2
igorw
0
340
LISP 1.5 Programmer's Manual: A Dramatic Reading
igorw
0
480
The Moral Character of Software
igorw
1
310
interdisciplinary computing (domcode)
igorw
0
320
miniKanren (clojure berlin)
igorw
1
330
Other Decks in Programming
See All in Programming
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
310
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.5k
Creating Composable Callables in Contemporary C++
rollbear
0
170
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
370
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
900
dRuby over BLE
makicamel
2
400
Vite+ Unified Toolchain for the Web
naokihaba
0
370
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
310
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
180
A2UI という光を覗いてみる
satohjohn
1
170
AIで効率化できた業務・日常
ochtum
0
150
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
120
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
800
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
250
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
170
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
850
Building Adaptive Systems
keathley
44
3.1k
Are puppies a ranking factor?
jonoalderson
1
3.7k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
The Pragmatic Product Professional
lauravandoore
37
7.3k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
210
Transcript
Stack a PHP interface for framework- agnostic code sharing
the HttpKernelInterface is a lie
@igorwesome
None
“Interface” Protocol Communication Message passing
Catherine Please, from The Noun Project
Paulo Sá Ferreira - Purple Matter, from The Noun Project
hi!
None
10010101110100100
1001010111010010000110101 Massimiliano Mauro, from The Noun Project
Sergey Shmidt, from The Noun Project aloha!
yay!
00101000011101100102
None
None
None
None
Universal Interface
None
10010111001010001011
1234 4321
foo bar baz foo baz Patrick n Hawaii, from The
Noun Project
foo moo Anuar Zhumaev, from The Noun Project
find src -name '*.php' | grep -iv tests | cut
-f2- -d/ | cut -f1 -d\. | awk '{ print length, $0 }' | sort -n | tr / \\ ;
Tim Boelaars, from The Noun Project
None
nc
/\_/\ / 0 0 \ ====v==== \ W / |
| _ / ___ \ / / / \ \ | (((-----)))-' / ( ___ \__.=|___E /
None
data Dmitry Baranovskiy, from The Noun Project
xinetd
None
/etc/xinet.d/<service> service <service> { disable = no socket_type = stream
protocol = tcp user = <user> wait = no server = /usr/local/bin/<program> }
/etc/xinet.d/fortune service fortune { disable = no socket_type = stream
protocol = tcp user = xinetd wait = no server = /usr/local/bin/fortune }
#!/bin/bash fortune | cowsay
$ nc <host> 7777
$ nc <host> 7777 ______________________________________ < Eat right, stay fit,
and die anyway. > -------------------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
/etc/xinet.d/cowsay service cowsay { disable = no socket_type = stream
protocol = tcp user = xinetd wait = no server = /usr/games/cowsay }
$ echo 'moo' | nc <host> 7778
$ echo 'moo' | nc <host> 7778 _____ < moo
> ----- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
#!/usr/bin/php <?php ! while (!feof(STDIN)) { echo transform(fgets(STDIN)); }
cgi
The Common Gateway Interface (CGI) [22]! allows an HTTP [1],
[4] server and a CGI! script to share responsibility for responding! to client requests. RFC 3875
xinetd tcp http httpd
http httpd script cgi
script env vars data headers data
GET / HTTP/1.1 Host: igor.io Accept: */* REQUEST_METHOD = GET
PATH_INFO = / HTTP_HOST = igor.io HTTP_ACCEPT = */* SERVER_NAME = igor.io
Content-Type: text/html ! <!DOCTYPE html> <html> ... </html>
fcgi
script
sockets are the new pipes
• 1991: HTTP • 1993: CGI • 1995: PHP •
1996: FastCGI
• 1997: Java Servlet • 2003: Python WSGI • 2007:
Ruby Rack • 2009: Perl PSGI • 2011: Symfony2 HttpKernelInterface
rack
class HelloWorld def call(env) [ 200, {"Content-Type" => "text/plain"}, ["Hello
world!"] ] end end
sapi
$_SERVER header echo exit
HttpKernelInterface
interface HttpKernelInterface! {! /*** @return Response */! public function handle(Request
$request);! }
sapi kernel
None
“legacy” apps: it’s all great until exit;
myths: !
myths: caching
myths: caching (use varnish)
myths: caching (use varnish) functional tests
CgiHttpKernel adapter from kernel to cgi functional test “legacy” apps
kernel CGI
kernel CGI anything!
$kernel = new CgiHttpKernel(__DIR__.'/app'); ! $request = Request::create('/index.php'); $response =
$kernel->handle($request); ! var_dump($response->getContent());
use Symfony\Component\HttpKernel\Client; ! $client = new Client($kernel); ! $crawler =
$client->request('GET', '/index.php');
caution: it’s slow (WIP: FcgiHttpKernel)
Where is the value?
REQ REP
fcgi roles
authorizer httpd responder filter
rack middlewares
HttpKernel middlewares
$app = new CallableHttpKernel(function ($request) { return new Response('Hello World!');
});
class Logger implements HttpKernelInterface { private $app; private $logger; !
public function __construct(HttpKernelInterface $app, LoggerInterface $logger) { $this->app = $app; $this->logger = $logger; } ! public function handle(Request $request, ...) { $response = $this->app->handle($request, $type, $catch); ! $this->log($request, $response); ! return $response; } ! private function log(Request $request, Response $response) { ... } }
$app = new Logger( $app, new Monolog\Logger() );
use Symfony\Component\HttpKernel\HttpCache\HttpCache; use Symfony\Component\HttpKernel\HttpCache\Store; $app = new HttpCache( $app, new
Store(__DIR__.'/cache') );
use Symfony\Component\HttpKernel\HttpCache\HttpCache; use Symfony\Component\HttpKernel\HttpCache\Store; $app = new HttpCache( $app, new
Store(__DIR__.'/cache') ); use varnish!
App Logger Authentication Session
None
do something before or after every request
different take on event listeners
class Foo implements HttpKernelInterface { private $app; ! public function
__construct(HttpKernelInterface $app) { $this->app = $app; } ! public function handle(Request $request, ...) { $response = $this->app->handle($request, $type, $catch); ! return $response; } } 1 2 3
UrlMap $blog = new Silex\Application(); ! $blog->get('/', function () {
return 'This is the blog!'; }); ! $app = new Stack\UrlMap($app, [ '/blog' => $blog, ]);
Session $app = new CallableHttpKernel(function ($request) { $session = $request->getSession();
... }); ! $app = new Stack\Session($app);
OAuth $app = new Igorw\Stack\OAuth($app, [ 'key' => 'foo', 'secret'
=> 'bar', 'callback_url' => 'http://localhost:8080/auth/verify', 'success_url' => '/', 'failure_url' => '/auth', ]); ! $app = new Stack\Session($app);
OAuth $request->attributes->get('oauth.token');
Composition!
$stack = (new Stack\Builder()) ->push('Stack\Session') ->push('Igorw\Stack\OAuth', [...]) ->push('Foo'); ! $app
= $stack->resolve($app);
• GeoIp • IpRestrict • Backstage • Basic Authentication •
Hawk • CORS Community
It doesn’t stop there
• Authentication • Debug toolbar • Injected routes • Signed
cookies • Asset management • Force SSL • Error handling
( )
Choose wisely
Michael Rowe, from The Noun Project
• joind.in/9355 • stackphp.com • @stackphp • @igorwesome • github.com/igorw/CgiHttpKernel