-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathct14.html
More file actions
472 lines (439 loc) · 16.3 KB
/
ct14.html
File metadata and controls
472 lines (439 loc) · 16.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PHP</title>
<meta name="description" content="PHP">
<meta name="author" content="Rasmus Lerdorf">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="/reveal.js/css/reveal.css">
<link rel="stylesheet" href="/reveal.js/css/theme/white.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="/reveal.js/lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? '/reveal.js/css/print/pdf.css' : '/reveal.js/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="/reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>PHP</h1>
<h3>PHP Craft</h3>
<h3>Cape Town</h3>
<h3>Apr.12, 2014</h3>
<a href="http://talks.php.net/ct14">http://talks.php.net/ct14</a><br><br>
<p>Rasmus Lerdorf<br>
<small><a href="http://twitter.com/@rasmus">@rasmus</a></small>
</p>
</section>
<section>
<h2 margin-bottom="2em">1993</h2><br>
<pre><code class="C">#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define ishex(x) (((x) >= '0' && (x) <= '9') || ((x) >= 'a' && \
(x) <= 'f') || ((x) >= 'A' && (x) <= 'F'))
int htoi(char *s) {
int value;
char c;
c = s[0];
if(isupper(c)) c = tolower(c);
value=(c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16;
c = s[1];
if(isupper(c)) c = tolower(c);
value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10;
return(value);
}
void main(int argc, char *argv[]) {
char *params, *data, *dest, *s, *tmp;
char *name, *age;
puts("Content-type: text/html\r\n");
puts("<HTML><HEAD><TITLE>Form Example</TITLE></HEAD>");
puts("<BODY><H1>My Example Form</H1>");
puts("<FORM action=\"form.cgi\" method=\"GET\">");
puts("Name: <INPUT type=\"text\" name=\"name\">");
puts("Age: <INPUT type=\"text\" name=\"age\">");
puts("<BR><INPUT type=\"submit\">");
puts("</FORM>");
data = getenv("QUERY_STRING");
if(data && *data) {
params = data; dest = data;
while(*data) {
if(*data=='+') *dest=' ';
else if(*data == '%' && ishex(*(data+1))&&ishex(*(data+2))) {
*dest = (char) htoi(data + 1);
data+=2;
} else *dest = *data;
data++;
dest++;
}
*dest = '\0';
s = strtok(params,"&");
do {
tmp = strchr(s,'=');
if(tmp) {
*tmp = '\0';
if(!strcmp(s,"name")) name = tmp+1;
else if(!strcmp(s,"age")) age = tmp+1;
}
} while(s=strtok(NULL,"&"));
printf("Hi %s, you are %s years old\n",name,age);
}
puts("</BODY></HTML>");
}
</code></pre>
</section>
<section>
<h2 margin-bottom="2em">1993</h2><br>
<pre><code class="Perl">use CGI qw(:standard);
print header;
print start_html('Form Example'),
h1('My Example Form'),
start_form,
"Name: ", textfield('name'),
p,
"Age: ", textfield('age'),
p,
submit,
end_form;
if(param()) {
print "Hi ",em(param('name')),
"You are ",em(param('age')),
" years old";
}
print end_html;</code></pre>
</section>
<section>
<h2 margin-bottom="2em">1994</h2><br>
<pre><code class="PHP"><html><head><title>Form Example</title></head>
<body><h1>My Example Form</h1>
<form action="form.phtml" method="POST">
Name: <input type="text" name="name">
Age: <input type="text" name="age">
<br><input type="submit">
</form>
<?if($name):?>
Hi <?echo $name?>, you are <?echo $age?> years old
<?endif?>
</body></html></code></pre>
</section>
<section>
<h3 class="p">Focus on the Ecosystem</h3>
<ul>
<li>LAMP wasn't an accident</li>
<li>Robustness, Performance and Security</li>
<li><font color="ff2233">♥</font> shared hosting ISPs</li>
</ul>
<h3 class="p">Scale</h3>
<ul>
<li>Scaling up is expected</li>
<li>Scaling down is surprisingly hard</li>
<li>Doing both is rocket science</li>
</ul>
</section>
<section>
<h3 class="p">Performance</h3>
<ul>
<li>mod_php</li>
<li>shared-nothing perfect sandbox model</li>
</ul>
<h3 class="p">Robustness</h3>
<ul>
<li>SQL LIMIT clause</li>
<li>Promote Prefork shared-nothing model</li>
</ul>
<h3 class="p">Security</h3>
<ul>
<li>max_execution_time</li>
<li>memory_limit</li>
<li>safe mode</li>
</ul>
</section>
<section>
<h3 class="p">What was he thinking?</h3>
<ul>
<li>Case insensitive function names?</li>
<li>Naming inconsistencies?</li>
<li>What's with the $ signs?</li>
<li>Globals?</li>
<li>register_globals?</li>
<li>magic_quotes?</li>
</ul>
<h3 class="p">OMGWTFBBQ?</h3>
<pre><code>array_search($needle, $haystack);
strstr($haystack, $needle);
in_array($needle, $haystack);
substr_count($haystack, $needle);
array_key_exists($needle, $haystack);
strchr($haystack, $needle);</code></pre>
</section>
<section>
<h2>2014</h2>
</section>
<section>
<section id="performance">
<h2 margin-bottom="2em">PHP 5.5</h2><br>
<h3 class="p">Performance Improvements</h3>
<ul>
<li>Nested calls</li>
<li>Call stack pre-allocated by compiler</li>
<li>Bundled opcode cache</li>
</ul>
</section>
<section id="generators">
<h4 class="p">✔ Generators</h4>
<pre><code>function xrange($start, $end) {
for ($i = $start; $i <= $end; $i ++) {
yield $i;
}
}
foreach (xrange(0, 5) as $i) {
echo $i, "\n";
}</code></pre>
</section>
<section id="coroutines">
<h4 class="p">✔ Coroutines</h4>
<pre><code>function logger($fileName) {
$fileHandle = fopen($fileName, 'a');
while (true) {
fwrite($fileHandle, yield . "\n");
}
}
$logger = logger(__DIR__ . '/log');
$logger->send('Foo');
$logger->send('Bar');</code></pre>
<p class="p">For an advanced explanation of coroutines, read this article by Nikita Popov</p>
<div align="" style="font-size: ; color: ; margin-left: ; margin-right: ; margin-top: ; margin-bottom: ;"><a href="http://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html" target="">Cooperative multitasking using coroutines</a></div><br />
</section>
<section id="finally">
<h4 class="p">✔ finally</h4>
<pre><code>$db = mysqli_connect();
try {
call_some_function($db);
} finally {
mysqli_close($db);
}</code></pre>
</section>
<section id="foreachlist">
<h4 class="p">✔ list() in foreach</h4>
<pre><code>$names = [ ['John','Smith'], ['Fred','Johnson'] ];
foreach($names as list($first,$last)) {
echo $first,$last;
}</code></pre>
</section>
<section id="constarray">
<h4 class="p">✔ Const array/string Dereferencing</h4>
<pre><code>echo array(1, 2, 3)[0]; //output 1
echo "foobar"[3]; //output b
echo [1,3,4][2]; //output 4</code></pre>
</section>
<section id="others">
<h4 class="p">✔ empty() support for functions/expressions</h4>
<h4 class="p">✔ curl upload functionality rewritten</h4>
<h4 class="p">✔ Simplified password hashing API</h4>
<pre><code>// Hash
$hash = password_hash("super secret",PASSWORD_BCRYPT);
// To validate $pwd against the stored hash
if (password_verify($pwd, $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}</code></pre>
</section>
<section id="php55_done">
<div align="" style="font-size: ; color: ; margin-left: ; margin-right: ; margin-top: ; margin-bottom: ;"><a href="http://php.net/migration55" target="">php.net/migration55</a></div><br />
</section> </section>
<section>
<section id="php56">
<h2 margin-bottom="2em">PHP 5.6</h2><br>
<div align="" style="font-size: 2em; color: ; margin-left: 0em; margin-right: ; margin-top: ; margin-bottom: ;"><a href="http://php.net/spec" target="">http://php.net/spec</a></div><br />
</section>
<section id="php56variadic">
<h4 class="p">✔ Variadic functions</h4>
<pre><code>class MySQL implements DB {
public function query($query, ...$params) {
$stmt = $this->pdo->prepare($query);
$stmt->execute($params);
return $stmt;
}
}
$q = 'SELECT * FROM users WHERE id = ?';
$user = $db->query($q, $userID)->fetch();</code></pre>
</section>
<section id="php56unpack">
<h4 class="p">✔ Argument Unpacking</h4>
<pre><code>// A better call_user_func_args
$args1 = [1, 2, 3];
$args2 = [4, 5, 6];
test(...$args1, ...$args2); // [1, 2, 3, 4, 5, 6]
test(1, 2, 3, ...$args2); // [1, 2, 3, 4, 5, 6]
test(...$args1, 4, 5, 6); // Fatal error: Cannot use positional argument after argument unpacking</code></pre>
</section>
<section id="php56constscalar">
<h4 class="p">✔ Constant scalar expressions</h4>
<pre><code>class Foo {
const FOO = 1 + 1;
const BAR = 1 << 1;
const GREETING = "HELLO";
const BAZ = self::GREETING." WORLD!"
}</code></pre>
</section>
<section id="php56pow">
<h4 class="p">✔ Add right-associative power operator **</h4>
<pre><code>echo 2 ** 3 ** 2; // 512 (not 64)
echo -3 ** 2; // -9 (not 9)
echo 1 - 3 ** 2; // -8
echo ~3 ** 2; // -10 (not 16)</code></pre>
</section>
<section id="php56opoverload">
<h4 class="p">✔ Internal operator overloading for internal features like GMP</h4>
<pre><code>echo 2**512;
echo "\n";
$n = gmp_init(2);
echo $n**512;</code></pre>
<pre><code>1.3407807929943E+154
13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096
</code></pre> </section>
<section id="php56use">
<h4 class="p">✔ use function and use const namespace imports</h4>
<pre><code>include 'template.inc';
include 'db.inc';
use function template\header, template\footer, db\query;
header('My Page');
query('select * from stuff');
footer();</code></pre>
</section>
<section id="php56_0">
<h4 class="p">✔ default_charset ini now applies to internal funcs</h4>
<h4 class="p">✔ SSL Peer verification by default</h4>
<h4 class="p">✔ openssl certificate fingerprints</h4>
<h4 class="p">✔ SAN x509 ext matching when verifying host names</h4>
<h4 class="p">✔ automatic DoS prevention of TLS renegotiation attacks</h4>
<h4 class="p">✔ and many more openssl-related options</h4>
</section>
<section id="php56_1">
<h4 class="p">✔ Asynchronous PostgreSQL database connections</h4>
<h4 class="p">✔ Non-blocking PostgreSQL queries</h4>
<h4 class="p">✔ New phpdbg SAPI</h4>
<h4 class="p">✔ Support for > 2GB file uploads</h4>
<h4 class="p">✔ The php://input stream is now re-usable</h4>
<h4 class="p">✔ Added hash_equals() for timing attack safe string comparison</h4>
<h4 class="p">✔ Added gost-crypto (CryptoPro S-box) hash algorithm</h4>
<h4 class="p">✔ FPM workers can now change their apparmor profile</h4>
<h4 class="p">✔ OCI8 Improvements</h4>
</section>
<section id="php56_done">
<div align="" style="font-size: ; color: ; margin-left: ; margin-right: ; margin-top: ; margin-bottom: ;"><a href="http://php.net/migration56" target="">php.net/migration56</a></div><br />
</section> </section>
<section>
<h2 margin-bottom="2em">Deploying Web Apps</h2><br>
<h3 class="p">Are your deploys atomic?</h3>
<h3 class="p">Are you sure?</h3>
<h4 class="p">What happens to a request that is currently executing when you deploy?</h4>
</section>
<section>
<h2 margin-bottom="2em">Deploying Web Apps</h2><br>
<img src="/presentations/slides/intro/dep1.png" width="642" height="300">
</section>
<section>
<h2 margin-bottom="2em">Deploying Web Apps</h2><br>
<h4 class="p">✔ Don't copy files into current document root</h4>
<h4 class="p">✔ Let existing requests finish on old code</h4>
<h4 class="p">✔ New requests start on new code</h4>
<h4 class="p">✔ Avoid clearing your opcode cache</h4>
<h4 class="p">✔ Minimal impact on production traffic</h4>
</section>
<section>
<h2 margin-bottom="2em">Deploying Web Apps</h2><br>
<img src="/presentations/slides/intro/dep2.png" width="680" height="428">
</section>
<section>
<h2 margin-bottom="2em">Deploying Web Apps</h2><br>
<img src="/presentations/slides/intro/dep3.png" width="680" height="428">
</section>
<section>
<h2 margin-bottom="2em">Deploying Web Apps</h2><br>
<h4 class="p">2 Document Root directories</h4>
<h4 class="p">Symlink /var/www/site toggles between them</h4>
<h4 class="p">realpath() symlink at the web server level</h4>
<h4 class="p">Set Document Root to symlink realpath</h4>
<h4 class="p">Never hardcode the document root in code</h4>
</section>
<section>
<h2 margin-bottom="2em">Deploying Web Apps</h2><br>
<h3 class="p">Apache</h3>
<h4 class="p">http://github.com/etsy/mod_realdoc</h4>
<h3 class="p">nginx</h3>
<h4 class="p">You can use $realpath_root</h4>
<p class="p">eg. fastcgi_param DOCUMENT_ROOT $realpath_root;</p>
<h3 class="p">PHP</h3>
<h4 class="p">http://github.com/etsy/incpath</h4>
</section>
<section>
<div align="" style="font-size: ; color: ; margin-left: ; margin-right: ; margin-top: ; margin-bottom: ;"><a href="http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/" target="">codeascraft.com/2013/07/01/atomic-deploys-at-etsy/</a></div><br />
</section>
<section>
<img src="/presentations/slides/intro/lovehack-white-1000.png" width="1001" height="421">
</section>
<section data-background="#000000">
<img src="/presentations/slides/intro/rasmus.jpg" width="523" height="700">
</section>
<section data-background="#000000">
<img src="/presentations/slides/intro/Greenland1.jpg" width="1024" height="685">
</section>
<section data-background="#000000">
<img src="/presentations/slides/intro/Greenland2.jpg" width="1024" height="685">
</section>
<section data-background="#000000">
<img src="/presentations/slides/intro/Greenland3.jpg" width="1024" height="685">
</section>
<section>
<h2>Work on things that matter (to you)</h2>
</section>
<section>
<h4 class="p">We are running out of things that can be solved in isolation with our keyboards</h4>
</section>
<section>
<img src="/presentations/slides/intro/barros1.png" width="480" height="320">
<img src="/presentations/slides/intro/barros2.jpg" width="250" height="196">
<img src="/presentations/slides/intro/barros3.jpg" width="250" height="367">
<img src="/presentations/slides/intro/sasa.jpg" width="600" height="400">
</section>
</div>
</div>
<script src="/reveal.js/lib/js/head.min.js"></script>
<script src="/reveal.js/js/reveal.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
transitionSpeed: 'fast',
// Optional reveal.js plugins
dependencies: [
{ src: '/reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: '/reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: '/reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: '/reveal.js/plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: '/reveal.js/plugin/zoom-js/zoom.js', async: true },
{ src: '/reveal.js/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>