cvs: presentations /slides/hpp 100000000000005C0000005C29D61F11.jpg 10000000000000610000006B74D8AABB.jpg 10000000000000690000004538A678CE.jpg
1000000000000128000001028A86AC92.png 10000000000001380000022E2F008F54.jpg 100000000000014E000000CECE055B08.png 10000000000001800000018C5EF7614E.png
10000000000001810000022E4B29F6FE.jpg 10000000000001C10000022ECC7E4B87.jpg 10000000000001D40000011AC4E008B1.png 100000000000022E000000DB1068505E.png
1000000000000263000001282402DA5D.png 100000000000031C00000400998C2499.jpg 404.xml Cache_File.inc Fibonacci_v1.php Fibonacci_v2.php Fibonacci_v2.php5
a_bad_example.xml advice.xml antiexample.xml bad_regex.php bad_sql1.php bad_sql2.php benchmarking.xml bottom_drawer.xml caching_eval.xml
caching_for_textstatistics.xml compiler_caches.xml compress.xml content_caching.xml data_path.xml delayed_initialization.php denormalization.xml
denormalized.php driving.xml dynamic_activation.xml extending_benchmarkiterate.xml external_cacheability.xml fibonacci_example.xml
file_get_contents.xml final_picture.xml first.php first_shot.xml gen_library.xml generating_a_trace.xml hexencode.php hexencode.xml
how_caching_works.xml how_ccache.xml idiosyncrasies.xml internal_functions.xml interpreting_a_trace.xml io_sizes.xml lazy_initialization.xml
lazy_initialization1.xml lifecycle.xml macro_subst.xml macro_subst2.xml macro_subst3.xml macro_subst4.xml macro_v1.inc macro_v2.inc macro_v3.inc
mastering.xml modgzip.xml netbuf.xml netbuf_ii.xml normalization.xml normalized.php ob.xml os_client.xml page62.xml perfect_fit.xml
persistent_cache_for_raw_data.xml phpzlib.xml pre_initialization.php problems.xml profiler_diagram_apd.xml profiling.xml recoding_c.xml
reimplementation.xml second.php serendipity_example.xml session_extension.xml setting_up_apd.xml setting_up_benchmarkiterate.xml
shameless_book_plug.xml simple_example.xml some_truisms.xml sqlopt1.xml sqlopt2.xml sqlopt3.xml sqlopt4.xml summarization1.sql summarization2.sql
summarization_example.xml summarizations.xml sys_ob.xml targetting_your_efforts.xml textstatistics_example.xml third.php titlepage.xml
tools_for_profiling.xml total_page_caching.xml what_caching.xml what_perf.xml when_optimize.xml wout_buff.png
| From: | Sterling Hughes | Date: | Mon, 28 Apr 2003 20:20:03 +0000 |
| Subject: | cvs: presentations /slides/hpp 100000000000005C0000005C29D61F11.jpg 10000000000000610000006B74D8AABB.jpg 10000000000000690000004538A678CE.jpg 1000000000000128000001028A86AC92.png 10000000000001380000022E2F008F54.jpg 100000000000014E000000CECE055B08.png 10000000000001800000018C5EF7614E.png 10000000000001810000022E4B29F6FE.jpg 10000000000001C10000022ECC7E4B87.jpg 10000000000001D40000011AC4E008B1.png 100000000000022E000000DB1068505E.png 1000000000000263000001282402DA5D.png 100000000000031C00000400998C2499.jpg 404.xml Cache_File.inc Fibonacci_v1.php Fibonacci_v2.php Fibonacci_v2.php5 a_bad_example.xml advice.xml antiexample.xml bad_regex.php bad_sql1.php bad_sql2.php benchmarking.xml bottom_drawer.xml caching_eval.xml caching_for_textstatistics.xml compiler_caches.xml compress.xml content_caching.xml data_path.xml delayed_initialization.php denormalization.xml denormalized.php driving.xml dynamic_activation.xml extending_benchmarkiterate.xml external_cacheability.xml fibonacci_example.xml file_get_contents.xml final_picture.xml first.php first_shot.xml gen_library.xml generating_a_trace.xml hexencode.php hexencode.xml how_caching_works.xml how_ccache.xml idiosyncrasies.xml internal_functions.xml interpreting_a_trace.xml io_sizes.xml lazy_initialization.xml lazy_initialization1.xml lifecycle.xml macro_subst.xml macro_subst2.xml macro_subst3.xml macro_subst4.xml macro_v1.inc macro_v2.inc macro_v3.inc mastering.xml modgzip.xml netbuf.xml netbuf_ii.xml normalization.xml normalized.php ob.xml os_client.xml page62.xml perfect_fit.xml persistent_cache_for_raw_data.xml phpzlib.xml pre_initialization.php problems.xml profiler_diagram_apd.xml profiling.xml recoding_c.xml reimplementation.xml second.php serendipity_example.xml session_extension.xml setting_up_apd.xml setting_up_benchmarkiterate.xml shameless_book_plug.xml simple_example.xml some_truisms.xml sqlopt1.xml sqlopt2.xml sqlopt3.xml sqlopt4.xml summarization1.sql summarization2.sql summarization_example.xml summarizations.xml sys_ob.xml targetting_your_efforts.xml textstatistics_example.xml third.php titlepage.xml tools_for_profiling.xml total_page_caching.xml what_caching.xml what_perf.xml when_optimize.xml wout_buff.png |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-668@lists.php.net to get a copy of this message | ||
sterling Mon Apr 28 16:20:03 2003 EDT
Added files:
/presentations/slides/hpp 100000000000005C0000005C29D61F11.jpg
10000000000000610000006B74D8AABB.jpg
10000000000000690000004538A678CE.jpg
1000000000000128000001028A86AC92.png
10000000000001380000022E2F008F54.jpg
100000000000014E000000CECE055B08.png
10000000000001800000018C5EF7614E.png
10000000000001810000022E4B29F6FE.jpg
10000000000001C10000022ECC7E4B87.jpg
10000000000001D40000011AC4E008B1.png
100000000000022E000000DB1068505E.png
1000000000000263000001282402DA5D.png
100000000000031C00000400998C2499.jpg
404.xml Cache_File.inc Fibonacci_v1.php
Fibonacci_v2.php Fibonacci_v2.php5
a_bad_example.xml advice.xml
antiexample.xml bad_regex.php
bad_sql1.php bad_sql2.php
benchmarking.xml bottom_drawer.xml
caching_eval.xml
caching_for_textstatistics.xml
compiler_caches.xml compress.xml
content_caching.xml data_path.xml
delayed_initialization.php
denormalization.xml denormalized.php
driving.xml dynamic_activation.xml
extending_benchmarkiterate.xml
external_cacheability.xml
fibonacci_example.xml
file_get_contents.xml final_picture.xml
first.php first_shot.xml gen_library.xml
generating_a_trace.xml hexencode.php
hexencode.xml how_caching_works.xml
how_ccache.xml idiosyncrasies.xml
internal_functions.xml
interpreting_a_trace.xml io_sizes.xml
lazy_initialization.xml
lazy_initialization1.xml lifecycle.xml
macro_subst.xml macro_subst2.xml
macro_subst3.xml macro_subst4.xml
macro_v1.inc macro_v2.inc macro_v3.inc
mastering.xml modgzip.xml netbuf.xml
netbuf_ii.xml normalization.xml
normalized.php ob.xml os_client.xml
page62.xml perfect_fit.xml
persistent_cache_for_raw_data.xml
phpzlib.xml pre_initialization.php
problems.xml profiler_diagram_apd.xml
profiling.xml recoding_c.xml
reimplementation.xml second.php
serendipity_example.xml
session_extension.xml setting_up_apd.xml
setting_up_benchmarkiterate.xml
shameless_book_plug.xml
simple_example.xml some_truisms.xml
sqlopt1.xml sqlopt2.xml sqlopt3.xml
sqlopt4.xml summarization1.sql
summarization2.sql
summarization_example.xml
summarizations.xml sys_ob.xml
targetting_your_efforts.xml
textstatistics_example.xml third.php
titlepage.xml tools_for_profiling.xml
total_page_caching.xml what_caching.xml
what_perf.xml when_optimize.xml
wout_buff.png
Log:
the slides and images
Index: presentations/slides/hpp/404.xml +++ presentations/slides/hpp/404.xml <slide title="Using ErrorDocument"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Change caching to write into your document root</blurb> <blurb> </blurb> <example filename="third.php" fontsize="1.7em"/> <blurb>Always link to %third.html% and set:</blurb> <example>ErrorDocument 404 /third/third.php</example> <blurb>In an appropriate place (%Directory% stanza or %.htaccess% file)</blurb> </slide> Index: presentations/slides/hpp/Cache_File.inc +++ presentations/slides/hpp/Cache_File.inc <?php class Cache_File { var $filename; var $tempfilename; var $expriration; var $fp; var $cachedir = '/cache'; function Cache_File($file, $exp=false) { $this->filename = $file; $this->expiration = $exp; } function getLoc() { return "{$this->cachedir}/{$this->filename}"; } function begin() { $this->tempfilename = $this->cachedir . '/' . $this->filename . '.' . getmypid(); $this->fp = fopen($this->tempfilename, "w"); if ($this->fp === false) { return false; } ob_start(); } function end() { $buffer = ob_get_contents(); ob_end_flush(); if(strlen($buffer)) { fwrite($this->fp, $buffer); fclose($this->fp); rename($this->tempfilename, $this->getLoc()); return true; } else { fclose($this->fp); unlink($this->tempfilename); return false; } } function put($buffer) { $this->fp = fopen($this->tempfilename, "w"); if ($this->fp === false) { return false; } fwrite($this->fp, $buffer); fclose($this->fp); rename($this->tempfilename, $this->getLoc()); return true; } function get() { $filename = $this->getLoc(); if($this->expiration) { $stat = @stat($filename); if($stat[9]) { if(time() > $stat[9] + $this->expiration) { unlink($filename); return false; } } } return @file_get_contents($filename); } } ?> Index: presentations/slides/hpp/Fibonacci_v1.php +++ presentations/slides/hpp/Fibonacci_v1.php <?php function Fib($n) { if ($n == 0 || $n == 1) { return 1; } else { return Fib($n - 2) + Fib($n - 1); } } ?> Index: presentations/slides/hpp/Fibonacci_v2.php +++ presentations/slides/hpp/Fibonacci_v2.php <?php $FV = array(0 => 1, 1 => 1); function Fib($n) { global $FV; if (!is_int($n) || $n < 0) { return 0; } if(!isset($FV[$n])) { $FV[$n] = Fib($n - 2) + Fib($n - 1); } return $FV[$n]; } ?> Index: presentations/slides/hpp/Fibonacci_v2.php5 +++ presentations/slides/hpp/Fibonacci_v2.php5 <?php class Fibonacci { static $values = array(0 => 1, 1 => 1); static function num($n) { if (!is_int($n) || $n < 0) { return 0; } if (!isset(self::$values[$n])) { self::$values[$n] = self::num($n -2) + self::num($n - 1); } return self::$values[$n]; } } ?> Index: presentations/slides/hpp/a_bad_example.xml +++ presentations/slides/hpp/a_bad_example.xml <slide title="A Bad Example"> <blurb>A Bad Example</blurb> <blurb>The previous example was poor. </blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/advice.xml +++ presentations/slides/hpp/advice.xml <slide title="Advice"> <blurb>Advice</blurb> <blurb>Never recode a PHP distribution function unless your patch is accepted into PHP</blurb> <blurb>Be aware of the increased maintenance needs</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/antiexample.xml +++ presentations/slides/hpp/antiexample.xml <slide title="Anti-Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> <![CDATA[<br/>]]> </blurb> <example fontsize="1.7em" title="O(n^2) Copies"><![CDATA[<?php $cat = create_function('$a,$b', 'return $a . $b;'); $str = array_reduce($array, $cat, 0); ?>]]></example> <example fontsize="1.7em" title="O(n) Copies"><![CDATA[<?php $count = count($array); for ($i = 0, $str = ""; $i < $count; $i++) { $str .= $array[$i]; } ?>]]></example> </slide> Index: presentations/slides/hpp/bad_regex.php +++ presentations/slides/hpp/bad_regex.php <?php $UNSAFE_HTML = array( "!javascript\s*:!is", "!vbscri?pt\s*:!is", "!<\s*embed.*swf!is", "!vbscri?pt\s*:!is", "!<[^>]*[^a-z]onabort\s*=!is", "!<[^>]*[^a-z]onblur\s*=!is", "!<[^>]*[^a-z]onchange\s*=!is", "!<[^>]*[^a-z]onfocus\s*=!is", "!<[^>]*[^a-z]onmouseout\s*=!is", "!<[^>]*[^a-z]onmouseover\s*=!is", "!<[^>]*[^a-z]onload\s*=!is", "!<[^>]*[^a-z]onreset\s*=!is", "!<[^>]*[^a-z]onselect\s*=!is", "!<[^>]*[^a-z]onsubmit\s*=!is", "!<[^>]*[^a-z]onunload\s*=!is", "!<[^>]*[^a-z]onerror\s*=!is", "!<[^>]*[^a-z]onclick\s*=!is" ); function unsafe_html($html) { global $UNSAFE_HTML; foreach ($UNSAFE_HTML as $match) { if (preg_match($match, $html, $matches)) { return $match; } } return false; } ?> Index: presentations/slides/hpp/bad_sql1.php +++ presentations/slides/hpp/bad_sql1.php <?php /* CREATE TABLE entries ( id int not null auto_increment, title varchar(128), topic varhcar(128), body text, primary key(id) ); */ function entries_between($begin, $end) { mysql_query("SELECT * from entries"); while ($array = mysql_fetch_assoc()) { if ($array['id'] < $begin || $array['id'] > $end) { continue; } $retval[] = $array; } return $retval; } ?> Index: presentations/slides/hpp/bad_sql2.php +++ presentations/slides/hpp/bad_sql2.php <?php /* CREATE TABLE entries ( entryid int not null auto_increment, title varchar(128), authorid int, topic varhcar(128), body text, primary key(entryid) ); CREATE TABLE authors ( authorid int not null auto_increment, name varchar(128), primary key(authorid) ); */ function entry_topic_directory($topic) { mysql_query("SELECT * FROM entries e, authors a WHERE topic = '$topic' AND e.authorid = a.authorid"); echo "<table>"; while ($array = mysql_fetch_assoc()) { ?> <tr><td><?= $array['$title'] ?></td> <td><?= $array['name'] ?></td></tr> <?php } } ?> Index: presentations/slides/hpp/benchmarking.xml +++ presentations/slides/hpp/benchmarking.xml <slide title="Benchmarking"> <blurb>Benchmarking</blurb> <blurb>Benchmarking allows us to compare alternative implementations in a sandboxed environment.</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/bottom_drawer.xml +++ presentations/slides/hpp/bottom_drawer.xml <slide title="Bottom Drawer Techniques"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Bottom Drawer Techniques</blurb> <blurb fontsize="3.5em">Techniques with rare/minor payoff</blurb> <blurb fontsize="3.5em">Loop Overuse</blurb> <blurb fontsize="3.5em">%include% vs. %include_once%</blurb> </slide> Index: presentations/slides/hpp/caching_eval.xml +++ presentations/slides/hpp/caching_eval.xml <slide title="Pros and Cons of Caching"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <list title="Pros"> <bullet>Potentially Immense speedup</bullet> <bullet>Decreased Resource Consumption</bullet> </list> <list title="Cons"> <bullet>Increase in Arch. Complexity</bullet> <bullet>Potential for stale or inconsistent data.</bullet> </list> </slide> Index: presentations/slides/hpp/caching_for_textstatistics.xml +++ presentations/slides/hpp/caching_for_textstatistics.xml <slide title="Caching for Text_Statistics"> <blurb>Caching for Text_Statistics</blurb> <blurb>Text Statistics is a PEAR package to calculate statistics for documents including readability scores. </blurb> <blurb>(WordFactory.php)</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/compiler_caches.xml +++ presentations/slides/hpp/compiler_caches.xml <slide title="Compiler Caches "> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb> </blurb> <list align="center" title="Compiler Caches"> <bullet>Highest effort/payoff ratio</bullet> <bullet>Many available options</bullet> <bullet marginleft="2.0em">APC</bullet> <bullet marginleft="2.0em">Bware Afterburner</bullet> <bullet marginleft="2.0em">ION Cube</bullet> <bullet marginleft="2.0em">Turck MMCache</bullet> <bullet marginleft="2.0em">Zend Accelerator</bullet> </list> </slide> Index: presentations/slides/hpp/compress.xml +++ presentations/slides/hpp/compress.xml <slide title="Content Compression"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Some browsers can accept certain content compressed.</blurb> <blurb fontsize="3.5em">We can trade some cpu cycles for reduced bandwidth usage.</blurb> <blurb fontsize="3.5em">Compression is usually a minor overhead.</blurb> </slide> Index: presentations/slides/hpp/content_caching.xml +++ presentations/slides/hpp/content_caching.xml <slide title="Caching Page Content"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb align="center" fontsize="3.5em">Writing static copies of pages or sections of pages completely avoids overhead of dynamic generation. </blurb> </slide> Index: presentations/slides/hpp/data_path.xml +++ presentations/slides/hpp/data_path.xml <slide title="The Path Of Data in PHP"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/><br/>]]></blurb> <image align="center" filename="100000000000022E000000DB1068505E.png" /> </slide> Index: presentations/slides/hpp/delayed_initialization.php +++ presentations/slides/hpp/delayed_initialization.php <?php function &us_states() { global $US_STATES; if(count($US_STATES)) { return $US_STATES; } $US_STATES['al'] = 'Alabama'; /* ... */ $US_STATES['wy'] = 'Wyoming'; return $US_STATES; } function country_abbrs() { global $COUNTRY_ABBRS; if(count($US_STATES)) { return $US_STATES; } $COUNTRY_ABBRS['al'] = 'Albania'; /* ... */ $COUNTRY_ABBRS['zi'] = 'Zimbabwe'; return $COUNTRY_ABBRS; } $states =& us_states(); ?> Index: presentations/slides/hpp/denormalization.xml +++ presentations/slides/hpp/denormalization.xml <slide title="De-Normalization "> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Denormalizing tables can reduce IO on frequently accessed tables.</blurb> <example filename="denormalized.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/denormalized.php +++ presentations/slides/hpp/denormalized.php <?php /* CREATE TABLE users ( userid int not null auto_increment, name varchar(128), attr1 varchar(128), attr2 varchar(128), attr3 varchar(128), attr4 varchar(128), primary key(userid) ); CREATE TABLE attributes ( userid int not null, key varchar(128), value varchar(128) ); */ function get_user($userid) { mysql_query("SELECT * FROM users WHERE userid = $userid"); $row = mysql_fetch_assoc(); foreach ($row as $key => $value) { $userinfo[$key] = $value; } } ?> Index: presentations/slides/hpp/driving.xml +++ presentations/slides/hpp/driving.xml <slide title="How's My Driving?"> <blurb> </blurb> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> </blurb> <blurb>Spot What is Wrong with these Regular expressions</blurb> <example filename="bad_regex.php" fontsize="1.8em"/> </slide> Index: presentations/slides/hpp/dynamic_activation.xml +++ presentations/slides/hpp/dynamic_activation.xml <slide title="Dynamic Activation"> <blurb>Dynamic Activation</blurb> <blurb>if($_GET[?debug?] == 1) {</blurb> <blurb>}</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/extending_benchmarkiterate.xml +++ presentations/slides/hpp/extending_benchmarkiterate.xml <slide title="Extending Benchmark_Iterate"> <blurb>Extending Benchmark_Iterate</blurb> <blurb>We?ll overload the run method of Benchmark_Iterate to allow for passing a data generation function.</blurb> <blurb>(Benchmark_RandomData.inc)</blurb> <blurb>(max2.php)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/external_cacheability.xml +++ presentations/slides/hpp/external_cacheability.xml <slide title="External Cacheability"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Set %Cache-Control% headers so external caches no how to respect your content.</blurb> </slide> Index: presentations/slides/hpp/fibonacci_example.xml +++ presentations/slides/hpp/fibonacci_example.xml <slide title="Fibonacci Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>By stashing data in a global variable, we can speed both initial computations (since %fib()% is recursive) as well as future invocations in the same process.</blurb> <example filename="Fibonacci_v1.php" title="Neive Fib()" fontsize="1.8em"/> <example filename="Fibonacci_v2.php" title="Fib() with Caching" fontsize="1.8em"/> <example filename="Fibonacci_v2.php5" title="PHP5 Fib()" fontsize="1.8em"/> </slide> Index: presentations/slides/hpp/file_get_contents.xml +++ presentations/slides/hpp/file_get_contents.xml <slide title="file_get_contents()"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <example><![CDATA[<?php $str = file_get_contents($file); ?>]]></example> <blurb align="center" fontsize="4.0em">vs.</blurb> <example><![CDATA[<?php $fp = fopen($file, 'r'); while (($line = fgets($fp)) !== false) { $str .= $line; } fclose($fp); ?>]]></example> </slide> Index: presentations/slides/hpp/final_picture.xml +++ presentations/slides/hpp/final_picture.xml <slide title="The Final Picture"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <image filename="1000000000000263000001282402DA5D.png" align="center"/> </slide> Index: presentations/slides/hpp/first.php +++ presentations/slides/hpp/first.php <?php if(file_exists("/cache/first.cache")) { $stat = @stat("/cache/first.cache"); if ($stat[9] && (time() > $stat[9] + 10)) { unlink("/cache/first.cache"); } else { include("/cache/first.cache"); return; } } $cachefp = fopen("/cache/first.cache", "w"); ob_start(); ?> <html> <body> <!-- Cacheable for a 10 sec period --> Today is <?= strftime("%A, %B %e %Y %H:%M:%S") ?> </body> </html> <?php if ($cachefp) { $file = ob_get_contents(); fwrite($cachefp, $file); ob_end_flush(); } ?> Index: presentations/slides/hpp/first_shot.xml +++ presentations/slides/hpp/first_shot.xml <slide title="A First Shot at Caching"> <example filename="first.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/gen_library.xml +++ presentations/slides/hpp/gen_library.xml <slide title="A Generalized Library"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>A generic library allows us to encapsulate our logic for easy usage. </blurb> <blurb> </blurb> <example filename="Cache_File.inc" fontsize="1.6em"/> </slide> Index: presentations/slides/hpp/generating_a_trace.xml +++ presentations/slides/hpp/generating_a_trace.xml <slide title="Generating A Trace"> <blurb>Generating A Trace</blurb> <blurb>(bad_regex.php)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/hexencode.php +++ presentations/slides/hpp/hexencode.php <?php function hexencode($data) { $ascii = unpack("C*", $data); $retval = ''; foreach ($ascii as $v) { $retval .= sprintf("%02x", $v); } return $retval; } function hexdecode($data) { $len = strlen($data); $retval = ''; for($i=0; $i < $len; $i+= 2) { $retval .= pack("C", hexdec( substr($data, $i, 2) ) ); } return $retval; } ?> Index: presentations/slides/hpp/hexencode.xml +++ presentations/slides/hpp/hexencode.xml <slide title="hexencode()"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Need to hex encode data for non-8 Bit Clean safe transport.</blurb> <blurb>For even moderately large data this can expend an immense amount of effort.</blurb> <example filename="hexencode.php" fontsize="1.7em" /> </slide> Index: presentations/slides/hpp/how_caching_works.xml +++ presentations/slides/hpp/how_caching_works.xml <slide title="How Caching Works"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <image filename="10000000000001800000018C5EF7614E.png" align="center"/> </slide> Index: presentations/slides/hpp/how_ccache.xml +++ presentations/slides/hpp/how_ccache.xml <slide title="Compiler Cache"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <image marginleft="1.0em" filename="10000000000001810000022E4B29F6FE.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet marginleft="1.0em">In general, each source file is compiled once</bullet> <bullet marginleft="1.0em">Compilation overhead becomes inconsequential</bullet> <bullet marginleft="1.0em">Cache introduces its own overhead due to dynamic nature of includes</bullet> </list> </slide> Index: presentations/slides/hpp/idiosyncrasies.xml +++ presentations/slides/hpp/idiosyncrasies.xml <slide title="Databases Idiosyncrasies"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list title="Oracle"> <bullet>Use Stored Procedures For DML</bullet> <bullet>Set %OciSetPreftech% when issuing multi-row selects.</bullet> </list> </slide> Index: presentations/slides/hpp/internal_functions.xml +++ presentations/slides/hpp/internal_functions.xml <slide title="Use Internal Functions"> <image align="right" filename="10000000000000690000004538A678CE.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Especially in tight loops</blurb> <blurb fontsize="3.5em">Especially in internal array iterators</blurb> </slide> Index: presentations/slides/hpp/interpreting_a_trace.xml +++ presentations/slides/hpp/interpreting_a_trace.xml <slide title="Interpreting A trace"> <blurb>Interpreting A trace</blurb> <blurb>(bad_regex.php)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/io_sizes.xml +++ presentations/slides/hpp/io_sizes.xml <slide title="Matching Your IO Sizes"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet>The goal is to pass off as much work to the kernel as efficiently as possible.</bullet> <bullet>Optimizes PHP<->OS Communication</bullet> <bullet>Reduces Number Of System Calls</bullet> </list> </slide> Index: presentations/slides/hpp/lazy_initialization.xml +++ presentations/slides/hpp/lazy_initialization.xml <slide title="Lazy Initialization"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Initialize large 'constant' arrays or expensive database information only when needed.</blurb> <example title="Bad" filename="pre_initialization.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/lazy_initialization1.xml +++ presentations/slides/hpp/lazy_initialization1.xml <slide title="Lazy Initialization (II)"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> </blurb> <example title="Good" filename="delayed_initialization.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/lifecycle.xml +++ presentations/slides/hpp/lifecycle.xml <slide title="Request Lifecycle"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <image filename="10000000000001380000022E2F008F54.jpg" marginleft="1.0em" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet>This cycle happens for every include file, not just for the "main" script</bullet> <bullet>Compilation can easily consume more time than execution</bullet> </list> </slide> Index: presentations/slides/hpp/macro_subst.xml +++ presentations/slides/hpp/macro_subst.xml <slide title="Macro Substitution"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <example><![CDATA[%{SALUTATION}% %{NAME}%, Your friend %{FRIENDNAME}% has sent you an e-card. In order to view it, please click below: %{ECARD}%]]></example> </slide> Index: presentations/slides/hpp/macro_subst2.xml +++ presentations/slides/hpp/macro_subst2.xml <slide title="Macro Substitution (II)"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> </blurb> <blurb>First implementation.</blurb> <example fontsize="1.7em" filename="macro_v1.inc" /> <blurb>It's %O(n*m)%.</blurb> </slide> Index: presentations/slides/hpp/macro_subst3.xml +++ presentations/slides/hpp/macro_subst3.xml <slide title="Macro Substitution (III)"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>%O(n)% implementation.</blurb> <blurb> </blurb> <example filename="macro_v2.inc" fontsize="1.6em"/> </slide> Index: presentations/slides/hpp/macro_subst4.xml +++ presentations/slides/hpp/macro_subst4.xml <slide title="Macro Substitution (IV)"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>%O(n)% Implementation.</blurb> <blurb> </blurb> <example filename="macro_v3.inc" fontsize="1.6em"/> </slide> Index: presentations/slides/hpp/macro_v1.inc +++ presentations/slides/hpp/macro_v1.inc <?php function expand_macros($text, &$macroset) { if ($text) { $text = preg_replace(array_keys($macroset), array_values($macroset), $text); } return $text; } ?> Index: presentations/slides/hpp/macro_v2.inc +++ presentations/slides/hpp/macro_v2.inc <?php function subfunc($sub, &$macros) { return array_key_exists($sub, $macros) ? $macros[$sub]: "{$sub}"; } function expand_macros3($text, &$macroset) { if ($text) { $text = preg_replace("/{([^}]*)}/e", "subfunc('\\1', \$macroset)", $text); } return $text; } ?> Index: presentations/slides/hpp/macro_v3.inc +++ presentations/slides/hpp/macro_v3.inc <?php function expand_macros_helper($sub) { $macros = $GLOBALS['macroset']; $sub = $sub[1]; return array_key_exists($sub, $macros) ? $macros[$sub] : "{$sub}"; } function expand_macros5($text, &$macroset) { $GLOBALS['macroset'] = $macroset; if ($text) { $text = preg_replace_callback("/{([^}]*)}/", 'expand_macros_helper', $text); } return $text; } ?> Index: presentations/slides/hpp/mastering.xml +++ presentations/slides/hpp/mastering.xml <slide title="Regular Expressions"> <image align="right" filename="10000000000000690000004538A678CE.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Regexps are incredibly powerful</blurb> <blurb fontsize="3.5em">Also easy to shoot yourself in the foot</blurb> </slide> Index: presentations/slides/hpp/modgzip.xml +++ presentations/slides/hpp/modgzip.xml <slide title="mod_gzip"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">A very nice apache module for compressing content</blurb> <blurb fontsize="3.5em">Can compress any content</blurb> <blurb fontsize="3.5em">Can switch on MIME Types and Browser Types</blurb> <blurb fontsize="3.5em">Uses Temporary Files</blurb> </slide> Index: presentations/slides/hpp/netbuf.xml +++ presentations/slides/hpp/netbuf.xml <slide title="Network Buffer Sizing"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Idea is to hand off entire page to the kernel without blocking</blurb> <blurb fontsize="3.5em">Apache: </blurb> <blurb fontsize="3.5em" marginleft="2.0em">%SendBufferSize = PageSize%</blurb> </slide> Index: presentations/slides/hpp/netbuf_ii.xml +++ presentations/slides/hpp/netbuf_ii.xml <slide title="Network Buffer Sizing (II)"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb fontsize="4.0em">OS (Linux)</blurb> <blurb marginleft="2.0em">%/proc/sys/net/ipv4/tcp_wmem%</blurb> <blurb marginleft="5.0em">%4096 16384 maxcontentsize%</blurb> <blurb marginleft="5.0em">%min default max%</blurb> <blurb marginleft="2.0em">%/proc/sys/net/ipv4/tcp_mem%</blurb> <blurb marginleft="2.0em">%(maxcontentsize * maxclients) / pagesize%</blurb> <blurb fontsize="4.0em">Be careful on low memory systems!</blurb> </slide> Index: presentations/slides/hpp/normalization.xml +++ presentations/slides/hpp/normalization.xml <slide title="Normalization"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Normalization makes your data model less brittle, and can speed certain classes of updates and deletes.</blurb> <example filename="normalized.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/normalized.php +++ presentations/slides/hpp/normalized.php <?php /* CREATE TABLE users ( userid int not null auto_increment, name varchar(128), primary key(userid) ); CREATE TABLE attributes ( userid int not null, key varchar(128), value varchar(128) ); */ function get_user($userid) { mysql_query("SELECT name FROM users WHERE userid = $userid"); $userid->name = mysql_fetch(); mysql_query("SELECT key, value FROM attributes a WHERE userid = $userid"); while(list($key, $value) = mysql_fetch()) { $userinfo[$key] = $value; } return $userinfo; } ?> Index: presentations/slides/hpp/ob.xml +++ presentations/slides/hpp/ob.xml <slide title="Output Buffering"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet>Efficient</bullet> <bullet>Flexible</bullet> <bullet>In your script with %ob_start()%</bullet> <bullet>Everywhere with %output_buffering = On% (~php.ini~)</bullet> </list> </slide> Index: presentations/slides/hpp/os_client.xml +++ presentations/slides/hpp/os_client.xml <slide title="OS <--> Client"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <image filename="1000000000000128000001028A86AC92.png" align="center" /> </slide> Index: presentations/slides/hpp/page62.xml +++ presentations/slides/hpp/page62.xml <slide title="page62"> <blurb>Persistent Cache For</blurb> <blurb>Raw Data</blurb> <blurb>DBMs and RDBMS support key-value pairs for easy storage of simple data</blurb> <blurb>Complex data requires serialization/deserialization</blurb> <blurb>Make sure your data is worth the trouble!</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/perfect_fit.xml +++ presentations/slides/hpp/perfect_fit.xml <slide title="Internal Problems"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">When 'perfect-fit' Internal Functions Suck</blurb> <blurb fontsize="3.5em">%parse_url()% prior to 4.2.x</blurb> <blurb fontsize="3.5em">It's a bug.</blurb> </slide> Index: presentations/slides/hpp/persistent_cache_for_raw_data.xml +++ presentations/slides/hpp/persistent_cache_for_raw_data.xml <slide title="Persistent Cache For Raw Data"> <blurb>Persistent Cache For</blurb> <blurb>Raw Data</blurb> <blurb>DBM files</blurb> <blurb>RDBMS</blurb> <blurb>Flat Files</blurb> <blurb>SYSV Shared Memory</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/phpzlib.xml +++ presentations/slides/hpp/phpzlib.xml <slide title="zlib.output_compression"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">A built-in output buffer handler</blurb> <blurb fontsize="3.5em">Set in %php.ini%</blurb> <blurb fontsize="3.5em">Cannot be used with a custom %output_handler%</blurb> </slide> Index: presentations/slides/hpp/pre_initialization.php +++ presentations/slides/hpp/pre_initialization.php <?php /* Geographic Constants */ $US_STATES['al'] = 'Alabama'; /* ... */ $US_STATES['wy'] = 'Wyoming'; $COUNTRY_ABBRS['al'] = 'Albania'; /* ... */ $COUNTRY_ABBRS['zi'] = 'Zimbabwe'; /* Geographic Functions */ function is_valid_zip($zipcode) { return preg_match("/\d{5}/", $zipcode); } ?> Index: presentations/slides/hpp/problems.xml +++ presentations/slides/hpp/problems.xml <slide title="Problems With Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet>Race condition</bullet> <bullet>Verbosity</bullet> </list> </slide> Index: presentations/slides/hpp/profiler_diagram_apd.xml +++ presentations/slides/hpp/profiler_diagram_apd.xml <slide title="Profiler Diagram (APD)"> <blurb>Profiler Diagram </blurb> <blurb>(APD)</blurb> <image filename="10000000000001C10000022ECC7E4B87.jpg" /> <blurb>Intercepts calls to zend_execute</blurb> <blurb>Generates trace of functions calls with timings</blurb> </slide> Index: presentations/slides/hpp/profiling.xml +++ presentations/slides/hpp/profiling.xml <slide title="Profiling"> <blurb>Profiling</blurb> <blurb>Identify Bottlenecks</blurb> <blurb>Track Resource Usage</blurb> <blurb>Generate Call Trees</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/recoding_c.xml +++ presentations/slides/hpp/recoding_c.xml <slide title="Recoding in C"> <blurb>Recoding in C</blurb> <blurb>The ?ultimate step? when an routine can not be re-implemented using a different algorithm.</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/reimplementation.xml +++ presentations/slides/hpp/reimplementation.xml <slide title="Redesigned Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <example filename="second.php" fontsize="1.7em" /> </slide> Index: presentations/slides/hpp/second.php +++ presentations/slides/hpp/second.php <?php require_once "Cache_File.inc"; $cache = new Cache_File("second.cache", 10); if($text = $cache->get()) { print $text; exit; } $cache->begin(); ?> <html> <body> <!-- Cacheable for a day --> Today is <?=strftime("%A, %B %e %Y %H:%M:%S")?> </body> </html> <?php $cache->end(); ?> Index: presentations/slides/hpp/serendipity_example.xml +++ presentations/slides/hpp/serendipity_example.xml <slide title="Serendipity Example"> <blurb>Serendipity Example</blurb> <blurb>(pprof.serendipity)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/session_extension.xml +++ presentations/slides/hpp/session_extension.xml <slide title="Session Extension"> <blurb>Session Extension</blurb> <blurb>PHPs Session extesion is a prime example. </blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/setting_up_apd.xml +++ presentations/slides/hpp/setting_up_apd.xml <slide title="Setting up APD"> <blurb>Setting up APD</blurb> <blurb>> pear install apd</blurb> <blurb>> cp apd.so </blurb> <blurb>/absolute/path/to/php_apd.so</blurb> <blurb>In php.ini add</blurb> </slide> Index: presentations/slides/hpp/setting_up_benchmarkiterate.xml +++ presentations/slides/hpp/setting_up_benchmarkiterate.xml <slide title="Setting up benchmark_iterate"> <blurb>Setting up benchmark_iterate</blurb> <blurb>pear install Benchmark_Iterate</blurb> <blurb>It?s that simple.</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/shameless_book_plug.xml +++ presentations/slides/hpp/shameless_book_plug.xml <slide title="Shameless Book Plug"> <blurb>Shameless Book Plug</blurb> <image filename="100000000000031C00000400998C2499.jpg" /> <blurb>Available Aug 2003</blurb> <blurb>From Sams Publishing</blurb> </slide> Index: presentations/slides/hpp/simple_example.xml +++ presentations/slides/hpp/simple_example.xml <slide title="Simple example"> <blurb>Simple example</blurb> <blurb>Let?s try and actually measure the difference between PHP and C function implementations. </blurb> <blurb>(max.php)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/some_truisms.xml +++ presentations/slides/hpp/some_truisms.xml <slide title="Some Truisms"> <blurb>Some Truisms</blurb> <blurb>Ahmdahl?s Law</blurb> <blurb>80/20 rule</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/sqlopt1.xml +++ presentations/slides/hpp/sqlopt1.xml <slide title="SQL Optimization"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> </blurb> <blurb>Use SQL to ensure you only fetch the rows you are interested in.</blurb> <example filename="bad_sql1.php" fontsize="1.7em" /> </slide> Index: presentations/slides/hpp/sqlopt2.xml +++ presentations/slides/hpp/sqlopt2.xml <slide title="SQL Optimization"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Especially when querying tables with large fields, only select the columns you really need.</blurb> <example filename="bad_sql2.php" fontsize="1.7em" /> </slide> Index: presentations/slides/hpp/sqlopt3.xml +++ presentations/slides/hpp/sqlopt3.xml <slide title="Sometimes Greed is Good"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">If you are going to use the majority of columns in a table on an average lifetime, especially the larger fields, pre-fetching all the fields is preferable to going back for seconds.</blurb> </slide> Index: presentations/slides/hpp/sqlopt4.xml +++ presentations/slides/hpp/sqlopt4.xml <slide title="In Conclusione"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list fontsize="3.5em"> <bullet>Keep DB Logic in the DB</bullet> <bullet>Ordering</bullet> <bullet>Conditionals</bullet> <bullet>Limit return sets</bullet> </list> </slide> Index: presentations/slides/hpp/summarization1.sql +++ presentations/slides/hpp/summarization1.sql SELECT count(*) FROM users WHERE type='member' Index: presentations/slides/hpp/summarization2.sql +++ presentations/slides/hpp/summarization2.sql SELECT value FROM summaries WHERE name='member_value' Index: presentations/slides/hpp/summarization_example.xml +++ presentations/slides/hpp/summarization_example.xml <slide title="Summarization Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb fontsize="3.2em">Instead of calling</blurb> <blurb> </blurb> <example type="sql" fontsize="1.8em" filename="summarization1.sql" /> <blurb fontsize="3.2em">If you frequently need that count, try storing the count in a separate table</blurb> <example fontsize="1.8em" type="sql" filename="summarization2.sql" /> <blurb fontsize="3.2em">Keep this value current with either a trigger, a co-executed statement, or via an external job (if some delay is acceptable)</blurb> </slide> Index: presentations/slides/hpp/summarizations.xml +++ presentations/slides/hpp/summarizations.xml <slide title="Summarizations"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Frequently accessed sums, counts, and other miscellaneous calculations from a database can be pre-calculated and stored in a summary table.</blurb> </slide> Index: presentations/slides/hpp/sys_ob.xml +++ presentations/slides/hpp/sys_ob.xml <slide title="Output Buffering"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <image title="Without Output Buffering" marginleft="2.0em" align="center" filename="wout_buff.png" /> <blurb> </blurb> <image title="With Output Buffering" marginleft="2.0em" align="center" filename="10000000000001D40000011AC4E008B1.png" /> </slide> Index: presentations/slides/hpp/targetting_your_efforts.xml +++ presentations/slides/hpp/targetting_your_efforts.xml <slide title="Targetting Your Efforts"> <blurb>Targetting Your Efforts</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/textstatistics_example.xml +++ presentations/slides/hpp/textstatistics_example.xml <slide title="Text_Statistics Example"> <blurb>Text_Statistics Example</blurb> <blurb>Cache the syllable counts for words when text parsing a document.</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/third.php +++ presentations/slides/hpp/third.php <?php require_once "Cache_File.inc"; $cache = new Cache_File("third.html", 10); $cache->cachedir = "./"; // ... ?> Index: presentations/slides/hpp/titlepage.xml +++ presentations/slides/hpp/titlepage.xml <slide title="Welcome"> <blurb><![CDATA[<br/>]]></blurb> <blurb align="center" fontsize="6.0em">High Performance PHP</blurb> <blurb align="center" fontsize="4.0em">International PHP Conference, Amsterdam</blurb> <blurb align="center">May 7, 2003</blurb> <link align="center" leader="George Schlossnagle, " href="mailto:george@omniti.com" text="george@omniti.com"/> <link align="center" leader="Sterling Hughes, " href="mailto:sterling@php.net" text="sterling@php.net"/> </slide> Index: presentations/slides/hpp/tools_for_profiling.xml +++ presentations/slides/hpp/tools_for_profiling.xml <slide title="Tools For Profiling"> <blurb>Tools For Profiling</blurb> <blurb>DBG </blurb> <blurb>(http://dd.cron.ru/dbg/)</blurb> <blurb>APD </blurb> <blurb>(PECL)</blurb> <blurb>Xdebug (http://xdebug.derickrethans.nl/)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/total_page_caching.xml +++ presentations/slides/hpp/total_page_caching.xml <slide title="Total Page Caching"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <image filename="100000000000014E000000CECE055B08.png" align="center"/> </slide> Index: presentations/slides/hpp/what_caching.xml +++ presentations/slides/hpp/what_caching.xml <slide title="What Caching Is"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb align="center" fontsize="3.5em">Caching is the recognition and exploitation of the fact that most "dynamic" data does not change every time you request it.</blurb> </slide> Index: presentations/slides/hpp/what_perf.xml +++ presentations/slides/hpp/what_perf.xml <slide title="What is Performance?"> <blurb><![CDATA[<br/><br/><br/><br/>]]></blurb> <blurb align="center" fontsize="3.5em">Ensuring that your application works correctly within required time constraints.</blurb> </slide> Index: presentations/slides/hpp/when_optimize.xml +++ presentations/slides/hpp/when_optimize.xml <slide title="When To Optimize?"> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em" align="center">~Premature Optimzation Is The Root of All Evil.~</blurb> <blurb marginleft="1.0em" align="center">- Donalid E. Knuth</blurb> </slide>
Index: presentations/slides/hpp/404.xml +++ presentations/slides/hpp/404.xml <slide title="Using ErrorDocument"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Change caching to write into your document root</blurb> <blurb> </blurb> <example filename="third.php" fontsize="1.7em"/> <blurb>Always link to %third.html% and set:</blurb> <example>ErrorDocument 404 /third/third.php</example> <blurb>In an appropriate place (%Directory% stanza or %.htaccess% file)</blurb> </slide> Index: presentations/slides/hpp/Cache_File.inc +++ presentations/slides/hpp/Cache_File.inc <?php class Cache_File { var $filename; var $tempfilename; var $expriration; var $fp; var $cachedir = '/cache'; function Cache_File($file, $exp=false) { $this->filename = $file; $this->expiration = $exp; } function getLoc() { return "{$this->cachedir}/{$this->filename}"; } function begin() { $this->tempfilename = $this->cachedir . '/' . $this->filename . '.' . getmypid(); $this->fp = fopen($this->tempfilename, "w"); if ($this->fp === false) { return false; } ob_start(); } function end() { $buffer = ob_get_contents(); ob_end_flush(); if(strlen($buffer)) { fwrite($this->fp, $buffer); fclose($this->fp); rename($this->tempfilename, $this->getLoc()); return true; } else { fclose($this->fp); unlink($this->tempfilename); return false; } } function put($buffer) { $this->fp = fopen($this->tempfilename, "w"); if ($this->fp === false) { return false; } fwrite($this->fp, $buffer); fclose($this->fp); rename($this->tempfilename, $this->getLoc()); return true; } function get() { $filename = $this->getLoc(); if($this->expiration) { $stat = @stat($filename); if($stat[9]) { if(time() > $stat[9] + $this->expiration) { unlink($filename); return false; } } } return @file_get_contents($filename); } } ?> Index: presentations/slides/hpp/Fibonacci_v1.php +++ presentations/slides/hpp/Fibonacci_v1.php <?php function Fib($n) { if ($n == 0 || $n == 1) { return 1; } else { return Fib($n - 2) + Fib($n - 1); } } ?> Index: presentations/slides/hpp/Fibonacci_v2.php +++ presentations/slides/hpp/Fibonacci_v2.php <?php $FV = array(0 => 1, 1 => 1); function Fib($n) { global $FV; if (!is_int($n) || $n < 0) { return 0; } if(!isset($FV[$n])) { $FV[$n] = Fib($n - 2) + Fib($n - 1); } return $FV[$n]; } ?> Index: presentations/slides/hpp/Fibonacci_v2.php5 +++ presentations/slides/hpp/Fibonacci_v2.php5 <?php class Fibonacci { static $values = array(0 => 1, 1 => 1); static function num($n) { if (!is_int($n) || $n < 0) { return 0; } if (!isset(self::$values[$n])) { self::$values[$n] = self::num($n -2) + self::num($n - 1); } return self::$values[$n]; } } ?> Index: presentations/slides/hpp/a_bad_example.xml +++ presentations/slides/hpp/a_bad_example.xml <slide title="A Bad Example"> <blurb>A Bad Example</blurb> <blurb>The previous example was poor. </blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/advice.xml +++ presentations/slides/hpp/advice.xml <slide title="Advice"> <blurb>Advice</blurb> <blurb>Never recode a PHP distribution function unless your patch is accepted into PHP</blurb> <blurb>Be aware of the increased maintenance needs</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/antiexample.xml +++ presentations/slides/hpp/antiexample.xml <slide title="Anti-Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> <![CDATA[<br/>]]> </blurb> <example fontsize="1.7em" title="O(n^2) Copies"><![CDATA[<?php $cat = create_function('$a,$b', 'return $a . $b;'); $str = array_reduce($array, $cat, 0); ?>]]></example> <example fontsize="1.7em" title="O(n) Copies"><![CDATA[<?php $count = count($array); for ($i = 0, $str = ""; $i < $count; $i++) { $str .= $array[$i]; } ?>]]></example> </slide> Index: presentations/slides/hpp/bad_regex.php +++ presentations/slides/hpp/bad_regex.php <?php $UNSAFE_HTML = array( "!javascript\s*:!is", "!vbscri?pt\s*:!is", "!<\s*embed.*swf!is", "!vbscri?pt\s*:!is", "!<[^>]*[^a-z]onabort\s*=!is", "!<[^>]*[^a-z]onblur\s*=!is", "!<[^>]*[^a-z]onchange\s*=!is", "!<[^>]*[^a-z]onfocus\s*=!is", "!<[^>]*[^a-z]onmouseout\s*=!is", "!<[^>]*[^a-z]onmouseover\s*=!is", "!<[^>]*[^a-z]onload\s*=!is", "!<[^>]*[^a-z]onreset\s*=!is", "!<[^>]*[^a-z]onselect\s*=!is", "!<[^>]*[^a-z]onsubmit\s*=!is", "!<[^>]*[^a-z]onunload\s*=!is", "!<[^>]*[^a-z]onerror\s*=!is", "!<[^>]*[^a-z]onclick\s*=!is" ); function unsafe_html($html) { global $UNSAFE_HTML; foreach ($UNSAFE_HTML as $match) { if (preg_match($match, $html, $matches)) { return $match; } } return false; } ?> Index: presentations/slides/hpp/bad_sql1.php +++ presentations/slides/hpp/bad_sql1.php <?php /* CREATE TABLE entries ( id int not null auto_increment, title varchar(128), topic varhcar(128), body text, primary key(id) ); */ function entries_between($begin, $end) { mysql_query("SELECT * from entries"); while ($array = mysql_fetch_assoc()) { if ($array['id'] < $begin || $array['id'] > $end) { continue; } $retval[] = $array; } return $retval; } ?> Index: presentations/slides/hpp/bad_sql2.php +++ presentations/slides/hpp/bad_sql2.php <?php /* CREATE TABLE entries ( entryid int not null auto_increment, title varchar(128), authorid int, topic varhcar(128), body text, primary key(entryid) ); CREATE TABLE authors ( authorid int not null auto_increment, name varchar(128), primary key(authorid) ); */ function entry_topic_directory($topic) { mysql_query("SELECT * FROM entries e, authors a WHERE topic = '$topic' AND e.authorid = a.authorid"); echo "<table>"; while ($array = mysql_fetch_assoc()) { ?> <tr><td><?= $array['$title'] ?></td> <td><?= $array['name'] ?></td></tr> <?php } } ?> Index: presentations/slides/hpp/benchmarking.xml +++ presentations/slides/hpp/benchmarking.xml <slide title="Benchmarking"> <blurb>Benchmarking</blurb> <blurb>Benchmarking allows us to compare alternative implementations in a sandboxed environment.</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/bottom_drawer.xml +++ presentations/slides/hpp/bottom_drawer.xml <slide title="Bottom Drawer Techniques"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Bottom Drawer Techniques</blurb> <blurb fontsize="3.5em">Techniques with rare/minor payoff</blurb> <blurb fontsize="3.5em">Loop Overuse</blurb> <blurb fontsize="3.5em">%include% vs. %include_once%</blurb> </slide> Index: presentations/slides/hpp/caching_eval.xml +++ presentations/slides/hpp/caching_eval.xml <slide title="Pros and Cons of Caching"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <list title="Pros"> <bullet>Potentially Immense speedup</bullet> <bullet>Decreased Resource Consumption</bullet> </list> <list title="Cons"> <bullet>Increase in Arch. Complexity</bullet> <bullet>Potential for stale or inconsistent data.</bullet> </list> </slide> Index: presentations/slides/hpp/caching_for_textstatistics.xml +++ presentations/slides/hpp/caching_for_textstatistics.xml <slide title="Caching for Text_Statistics"> <blurb>Caching for Text_Statistics</blurb> <blurb>Text Statistics is a PEAR package to calculate statistics for documents including readability scores. </blurb> <blurb>(WordFactory.php)</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/compiler_caches.xml +++ presentations/slides/hpp/compiler_caches.xml <slide title="Compiler Caches "> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb> </blurb> <list align="center" title="Compiler Caches"> <bullet>Highest effort/payoff ratio</bullet> <bullet>Many available options</bullet> <bullet marginleft="2.0em">APC</bullet> <bullet marginleft="2.0em">Bware Afterburner</bullet> <bullet marginleft="2.0em">ION Cube</bullet> <bullet marginleft="2.0em">Turck MMCache</bullet> <bullet marginleft="2.0em">Zend Accelerator</bullet> </list> </slide> Index: presentations/slides/hpp/compress.xml +++ presentations/slides/hpp/compress.xml <slide title="Content Compression"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Some browsers can accept certain content compressed.</blurb> <blurb fontsize="3.5em">We can trade some cpu cycles for reduced bandwidth usage.</blurb> <blurb fontsize="3.5em">Compression is usually a minor overhead.</blurb> </slide> Index: presentations/slides/hpp/content_caching.xml +++ presentations/slides/hpp/content_caching.xml <slide title="Caching Page Content"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb align="center" fontsize="3.5em">Writing static copies of pages or sections of pages completely avoids overhead of dynamic generation. </blurb> </slide> Index: presentations/slides/hpp/data_path.xml +++ presentations/slides/hpp/data_path.xml <slide title="The Path Of Data in PHP"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/><br/>]]></blurb> <image align="center" filename="100000000000022E000000DB1068505E.png" /> </slide> Index: presentations/slides/hpp/delayed_initialization.php +++ presentations/slides/hpp/delayed_initialization.php <?php function &us_states() { global $US_STATES; if(count($US_STATES)) { return $US_STATES; } $US_STATES['al'] = 'Alabama'; /* ... */ $US_STATES['wy'] = 'Wyoming'; return $US_STATES; } function country_abbrs() { global $COUNTRY_ABBRS; if(count($US_STATES)) { return $US_STATES; } $COUNTRY_ABBRS['al'] = 'Albania'; /* ... */ $COUNTRY_ABBRS['zi'] = 'Zimbabwe'; return $COUNTRY_ABBRS; } $states =& us_states(); ?> Index: presentations/slides/hpp/denormalization.xml +++ presentations/slides/hpp/denormalization.xml <slide title="De-Normalization "> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Denormalizing tables can reduce IO on frequently accessed tables.</blurb> <example filename="denormalized.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/denormalized.php +++ presentations/slides/hpp/denormalized.php <?php /* CREATE TABLE users ( userid int not null auto_increment, name varchar(128), attr1 varchar(128), attr2 varchar(128), attr3 varchar(128), attr4 varchar(128), primary key(userid) ); CREATE TABLE attributes ( userid int not null, key varchar(128), value varchar(128) ); */ function get_user($userid) { mysql_query("SELECT * FROM users WHERE userid = $userid"); $row = mysql_fetch_assoc(); foreach ($row as $key => $value) { $userinfo[$key] = $value; } } ?> Index: presentations/slides/hpp/driving.xml +++ presentations/slides/hpp/driving.xml <slide title="How's My Driving?"> <blurb> </blurb> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> </blurb> <blurb>Spot What is Wrong with these Regular expressions</blurb> <example filename="bad_regex.php" fontsize="1.8em"/> </slide> Index: presentations/slides/hpp/dynamic_activation.xml +++ presentations/slides/hpp/dynamic_activation.xml <slide title="Dynamic Activation"> <blurb>Dynamic Activation</blurb> <blurb>if($_GET[?debug?] == 1) {</blurb> <blurb>}</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/extending_benchmarkiterate.xml +++ presentations/slides/hpp/extending_benchmarkiterate.xml <slide title="Extending Benchmark_Iterate"> <blurb>Extending Benchmark_Iterate</blurb> <blurb>We?ll overload the run method of Benchmark_Iterate to allow for passing a data generation function.</blurb> <blurb>(Benchmark_RandomData.inc)</blurb> <blurb>(max2.php)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/external_cacheability.xml +++ presentations/slides/hpp/external_cacheability.xml <slide title="External Cacheability"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Set %Cache-Control% headers so external caches no how to respect your content.</blurb> </slide> Index: presentations/slides/hpp/fibonacci_example.xml +++ presentations/slides/hpp/fibonacci_example.xml <slide title="Fibonacci Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>By stashing data in a global variable, we can speed both initial computations (since %fib()% is recursive) as well as future invocations in the same process.</blurb> <example filename="Fibonacci_v1.php" title="Neive Fib()" fontsize="1.8em"/> <example filename="Fibonacci_v2.php" title="Fib() with Caching" fontsize="1.8em"/> <example filename="Fibonacci_v2.php5" title="PHP5 Fib()" fontsize="1.8em"/> </slide> Index: presentations/slides/hpp/file_get_contents.xml +++ presentations/slides/hpp/file_get_contents.xml <slide title="file_get_contents()"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <example><![CDATA[<?php $str = file_get_contents($file); ?>]]></example> <blurb align="center" fontsize="4.0em">vs.</blurb> <example><![CDATA[<?php $fp = fopen($file, 'r'); while (($line = fgets($fp)) !== false) { $str .= $line; } fclose($fp); ?>]]></example> </slide> Index: presentations/slides/hpp/final_picture.xml +++ presentations/slides/hpp/final_picture.xml <slide title="The Final Picture"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <image filename="1000000000000263000001282402DA5D.png" align="center"/> </slide> Index: presentations/slides/hpp/first.php +++ presentations/slides/hpp/first.php <?php if(file_exists("/cache/first.cache")) { $stat = @stat("/cache/first.cache"); if ($stat[9] && (time() > $stat[9] + 10)) { unlink("/cache/first.cache"); } else { include("/cache/first.cache"); return; } } $cachefp = fopen("/cache/first.cache", "w"); ob_start(); ?> <html> <body> <!-- Cacheable for a 10 sec period --> Today is <?= strftime("%A, %B %e %Y %H:%M:%S") ?> </body> </html> <?php if ($cachefp) { $file = ob_get_contents(); fwrite($cachefp, $file); ob_end_flush(); } ?> Index: presentations/slides/hpp/first_shot.xml +++ presentations/slides/hpp/first_shot.xml <slide title="A First Shot at Caching"> <example filename="first.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/gen_library.xml +++ presentations/slides/hpp/gen_library.xml <slide title="A Generalized Library"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>A generic library allows us to encapsulate our logic for easy usage. </blurb> <blurb> </blurb> <example filename="Cache_File.inc" fontsize="1.6em"/> </slide> Index: presentations/slides/hpp/generating_a_trace.xml +++ presentations/slides/hpp/generating_a_trace.xml <slide title="Generating A Trace"> <blurb>Generating A Trace</blurb> <blurb>(bad_regex.php)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/hexencode.php +++ presentations/slides/hpp/hexencode.php <?php function hexencode($data) { $ascii = unpack("C*", $data); $retval = ''; foreach ($ascii as $v) { $retval .= sprintf("%02x", $v); } return $retval; } function hexdecode($data) { $len = strlen($data); $retval = ''; for($i=0; $i < $len; $i+= 2) { $retval .= pack("C", hexdec( substr($data, $i, 2) ) ); } return $retval; } ?> Index: presentations/slides/hpp/hexencode.xml +++ presentations/slides/hpp/hexencode.xml <slide title="hexencode()"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Need to hex encode data for non-8 Bit Clean safe transport.</blurb> <blurb>For even moderately large data this can expend an immense amount of effort.</blurb> <example filename="hexencode.php" fontsize="1.7em" /> </slide> Index: presentations/slides/hpp/how_caching_works.xml +++ presentations/slides/hpp/how_caching_works.xml <slide title="How Caching Works"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <image filename="10000000000001800000018C5EF7614E.png" align="center"/> </slide> Index: presentations/slides/hpp/how_ccache.xml +++ presentations/slides/hpp/how_ccache.xml <slide title="Compiler Cache"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <image marginleft="1.0em" filename="10000000000001810000022E4B29F6FE.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet marginleft="1.0em">In general, each source file is compiled once</bullet> <bullet marginleft="1.0em">Compilation overhead becomes inconsequential</bullet> <bullet marginleft="1.0em">Cache introduces its own overhead due to dynamic nature of includes</bullet> </list> </slide> Index: presentations/slides/hpp/idiosyncrasies.xml +++ presentations/slides/hpp/idiosyncrasies.xml <slide title="Databases Idiosyncrasies"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list title="Oracle"> <bullet>Use Stored Procedures For DML</bullet> <bullet>Set %OciSetPreftech% when issuing multi-row selects.</bullet> </list> </slide> Index: presentations/slides/hpp/internal_functions.xml +++ presentations/slides/hpp/internal_functions.xml <slide title="Use Internal Functions"> <image align="right" filename="10000000000000690000004538A678CE.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Especially in tight loops</blurb> <blurb fontsize="3.5em">Especially in internal array iterators</blurb> </slide> Index: presentations/slides/hpp/interpreting_a_trace.xml +++ presentations/slides/hpp/interpreting_a_trace.xml <slide title="Interpreting A trace"> <blurb>Interpreting A trace</blurb> <blurb>(bad_regex.php)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/io_sizes.xml +++ presentations/slides/hpp/io_sizes.xml <slide title="Matching Your IO Sizes"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet>The goal is to pass off as much work to the kernel as efficiently as possible.</bullet> <bullet>Optimizes PHP<->OS Communication</bullet> <bullet>Reduces Number Of System Calls</bullet> </list> </slide> Index: presentations/slides/hpp/lazy_initialization.xml +++ presentations/slides/hpp/lazy_initialization.xml <slide title="Lazy Initialization"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Initialize large 'constant' arrays or expensive database information only when needed.</blurb> <example title="Bad" filename="pre_initialization.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/lazy_initialization1.xml +++ presentations/slides/hpp/lazy_initialization1.xml <slide title="Lazy Initialization (II)"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> </blurb> <example title="Good" filename="delayed_initialization.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/lifecycle.xml +++ presentations/slides/hpp/lifecycle.xml <slide title="Request Lifecycle"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <image filename="10000000000001380000022E2F008F54.jpg" marginleft="1.0em" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet>This cycle happens for every include file, not just for the "main" script</bullet> <bullet>Compilation can easily consume more time than execution</bullet> </list> </slide> Index: presentations/slides/hpp/macro_subst.xml +++ presentations/slides/hpp/macro_subst.xml <slide title="Macro Substitution"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <example><![CDATA[%{SALUTATION}% %{NAME}%, Your friend %{FRIENDNAME}% has sent you an e-card. In order to view it, please click below: %{ECARD}%]]></example> </slide> Index: presentations/slides/hpp/macro_subst2.xml +++ presentations/slides/hpp/macro_subst2.xml <slide title="Macro Substitution (II)"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> </blurb> <blurb>First implementation.</blurb> <example fontsize="1.7em" filename="macro_v1.inc" /> <blurb>It's %O(n*m)%.</blurb> </slide> Index: presentations/slides/hpp/macro_subst3.xml +++ presentations/slides/hpp/macro_subst3.xml <slide title="Macro Substitution (III)"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>%O(n)% implementation.</blurb> <blurb> </blurb> <example filename="macro_v2.inc" fontsize="1.6em"/> </slide> Index: presentations/slides/hpp/macro_subst4.xml +++ presentations/slides/hpp/macro_subst4.xml <slide title="Macro Substitution (IV)"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>%O(n)% Implementation.</blurb> <blurb> </blurb> <example filename="macro_v3.inc" fontsize="1.6em"/> </slide> Index: presentations/slides/hpp/macro_v1.inc +++ presentations/slides/hpp/macro_v1.inc <?php function expand_macros($text, &$macroset) { if ($text) { $text = preg_replace(array_keys($macroset), array_values($macroset), $text); } return $text; } ?> Index: presentations/slides/hpp/macro_v2.inc +++ presentations/slides/hpp/macro_v2.inc <?php function subfunc($sub, &$macros) { return array_key_exists($sub, $macros) ? $macros[$sub]: "{$sub}"; } function expand_macros3($text, &$macroset) { if ($text) { $text = preg_replace("/{([^}]*)}/e", "subfunc('\\1', \$macroset)", $text); } return $text; } ?> Index: presentations/slides/hpp/macro_v3.inc +++ presentations/slides/hpp/macro_v3.inc <?php function expand_macros_helper($sub) { $macros = $GLOBALS['macroset']; $sub = $sub[1]; return array_key_exists($sub, $macros) ? $macros[$sub] : "{$sub}"; } function expand_macros5($text, &$macroset) { $GLOBALS['macroset'] = $macroset; if ($text) { $text = preg_replace_callback("/{([^}]*)}/", 'expand_macros_helper', $text); } return $text; } ?> Index: presentations/slides/hpp/mastering.xml +++ presentations/slides/hpp/mastering.xml <slide title="Regular Expressions"> <image align="right" filename="10000000000000690000004538A678CE.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Regexps are incredibly powerful</blurb> <blurb fontsize="3.5em">Also easy to shoot yourself in the foot</blurb> </slide> Index: presentations/slides/hpp/modgzip.xml +++ presentations/slides/hpp/modgzip.xml <slide title="mod_gzip"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">A very nice apache module for compressing content</blurb> <blurb fontsize="3.5em">Can compress any content</blurb> <blurb fontsize="3.5em">Can switch on MIME Types and Browser Types</blurb> <blurb fontsize="3.5em">Uses Temporary Files</blurb> </slide> Index: presentations/slides/hpp/netbuf.xml +++ presentations/slides/hpp/netbuf.xml <slide title="Network Buffer Sizing"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Idea is to hand off entire page to the kernel without blocking</blurb> <blurb fontsize="3.5em">Apache: </blurb> <blurb fontsize="3.5em" marginleft="2.0em">%SendBufferSize = PageSize%</blurb> </slide> Index: presentations/slides/hpp/netbuf_ii.xml +++ presentations/slides/hpp/netbuf_ii.xml <slide title="Network Buffer Sizing (II)"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb fontsize="4.0em">OS (Linux)</blurb> <blurb marginleft="2.0em">%/proc/sys/net/ipv4/tcp_wmem%</blurb> <blurb marginleft="5.0em">%4096 16384 maxcontentsize%</blurb> <blurb marginleft="5.0em">%min default max%</blurb> <blurb marginleft="2.0em">%/proc/sys/net/ipv4/tcp_mem%</blurb> <blurb marginleft="2.0em">%(maxcontentsize * maxclients) / pagesize%</blurb> <blurb fontsize="4.0em">Be careful on low memory systems!</blurb> </slide> Index: presentations/slides/hpp/normalization.xml +++ presentations/slides/hpp/normalization.xml <slide title="Normalization"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Normalization makes your data model less brittle, and can speed certain classes of updates and deletes.</blurb> <example filename="normalized.php" fontsize="1.7em"/> </slide> Index: presentations/slides/hpp/normalized.php +++ presentations/slides/hpp/normalized.php <?php /* CREATE TABLE users ( userid int not null auto_increment, name varchar(128), primary key(userid) ); CREATE TABLE attributes ( userid int not null, key varchar(128), value varchar(128) ); */ function get_user($userid) { mysql_query("SELECT name FROM users WHERE userid = $userid"); $userid->name = mysql_fetch(); mysql_query("SELECT key, value FROM attributes a WHERE userid = $userid"); while(list($key, $value) = mysql_fetch()) { $userinfo[$key] = $value; } return $userinfo; } ?> Index: presentations/slides/hpp/ob.xml +++ presentations/slides/hpp/ob.xml <slide title="Output Buffering"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet>Efficient</bullet> <bullet>Flexible</bullet> <bullet>In your script with %ob_start()%</bullet> <bullet>Everywhere with %output_buffering = On% (~php.ini~)</bullet> </list> </slide> Index: presentations/slides/hpp/os_client.xml +++ presentations/slides/hpp/os_client.xml <slide title="OS <--> Client"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <image filename="1000000000000128000001028A86AC92.png" align="center" /> </slide> Index: presentations/slides/hpp/page62.xml +++ presentations/slides/hpp/page62.xml <slide title="page62"> <blurb>Persistent Cache For</blurb> <blurb>Raw Data</blurb> <blurb>DBMs and RDBMS support key-value pairs for easy storage of simple data</blurb> <blurb>Complex data requires serialization/deserialization</blurb> <blurb>Make sure your data is worth the trouble!</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/perfect_fit.xml +++ presentations/slides/hpp/perfect_fit.xml <slide title="Internal Problems"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">When 'perfect-fit' Internal Functions Suck</blurb> <blurb fontsize="3.5em">%parse_url()% prior to 4.2.x</blurb> <blurb fontsize="3.5em">It's a bug.</blurb> </slide> Index: presentations/slides/hpp/persistent_cache_for_raw_data.xml +++ presentations/slides/hpp/persistent_cache_for_raw_data.xml <slide title="Persistent Cache For Raw Data"> <blurb>Persistent Cache For</blurb> <blurb>Raw Data</blurb> <blurb>DBM files</blurb> <blurb>RDBMS</blurb> <blurb>Flat Files</blurb> <blurb>SYSV Shared Memory</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/phpzlib.xml +++ presentations/slides/hpp/phpzlib.xml <slide title="zlib.output_compression"> <image align="right" filename="10000000000000610000006B74D8AABB.jpg" /> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">A built-in output buffer handler</blurb> <blurb fontsize="3.5em">Set in %php.ini%</blurb> <blurb fontsize="3.5em">Cannot be used with a custom %output_handler%</blurb> </slide> Index: presentations/slides/hpp/pre_initialization.php +++ presentations/slides/hpp/pre_initialization.php <?php /* Geographic Constants */ $US_STATES['al'] = 'Alabama'; /* ... */ $US_STATES['wy'] = 'Wyoming'; $COUNTRY_ABBRS['al'] = 'Albania'; /* ... */ $COUNTRY_ABBRS['zi'] = 'Zimbabwe'; /* Geographic Functions */ function is_valid_zip($zipcode) { return preg_match("/\d{5}/", $zipcode); } ?> Index: presentations/slides/hpp/problems.xml +++ presentations/slides/hpp/problems.xml <slide title="Problems With Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list> <bullet>Race condition</bullet> <bullet>Verbosity</bullet> </list> </slide> Index: presentations/slides/hpp/profiler_diagram_apd.xml +++ presentations/slides/hpp/profiler_diagram_apd.xml <slide title="Profiler Diagram (APD)"> <blurb>Profiler Diagram </blurb> <blurb>(APD)</blurb> <image filename="10000000000001C10000022ECC7E4B87.jpg" /> <blurb>Intercepts calls to zend_execute</blurb> <blurb>Generates trace of functions calls with timings</blurb> </slide> Index: presentations/slides/hpp/profiling.xml +++ presentations/slides/hpp/profiling.xml <slide title="Profiling"> <blurb>Profiling</blurb> <blurb>Identify Bottlenecks</blurb> <blurb>Track Resource Usage</blurb> <blurb>Generate Call Trees</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/recoding_c.xml +++ presentations/slides/hpp/recoding_c.xml <slide title="Recoding in C"> <blurb>Recoding in C</blurb> <blurb>The ?ultimate step? when an routine can not be re-implemented using a different algorithm.</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/reimplementation.xml +++ presentations/slides/hpp/reimplementation.xml <slide title="Redesigned Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <example filename="second.php" fontsize="1.7em" /> </slide> Index: presentations/slides/hpp/second.php +++ presentations/slides/hpp/second.php <?php require_once "Cache_File.inc"; $cache = new Cache_File("second.cache", 10); if($text = $cache->get()) { print $text; exit; } $cache->begin(); ?> <html> <body> <!-- Cacheable for a day --> Today is <?=strftime("%A, %B %e %Y %H:%M:%S")?> </body> </html> <?php $cache->end(); ?> Index: presentations/slides/hpp/serendipity_example.xml +++ presentations/slides/hpp/serendipity_example.xml <slide title="Serendipity Example"> <blurb>Serendipity Example</blurb> <blurb>(pprof.serendipity)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/session_extension.xml +++ presentations/slides/hpp/session_extension.xml <slide title="Session Extension"> <blurb>Session Extension</blurb> <blurb>PHPs Session extesion is a prime example. </blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/setting_up_apd.xml +++ presentations/slides/hpp/setting_up_apd.xml <slide title="Setting up APD"> <blurb>Setting up APD</blurb> <blurb>> pear install apd</blurb> <blurb>> cp apd.so </blurb> <blurb>/absolute/path/to/php_apd.so</blurb> <blurb>In php.ini add</blurb> </slide> Index: presentations/slides/hpp/setting_up_benchmarkiterate.xml +++ presentations/slides/hpp/setting_up_benchmarkiterate.xml <slide title="Setting up benchmark_iterate"> <blurb>Setting up benchmark_iterate</blurb> <blurb>pear install Benchmark_Iterate</blurb> <blurb>It?s that simple.</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/shameless_book_plug.xml +++ presentations/slides/hpp/shameless_book_plug.xml <slide title="Shameless Book Plug"> <blurb>Shameless Book Plug</blurb> <image filename="100000000000031C00000400998C2499.jpg" /> <blurb>Available Aug 2003</blurb> <blurb>From Sams Publishing</blurb> </slide> Index: presentations/slides/hpp/simple_example.xml +++ presentations/slides/hpp/simple_example.xml <slide title="Simple example"> <blurb>Simple example</blurb> <blurb>Let?s try and actually measure the difference between PHP and C function implementations. </blurb> <blurb>(max.php)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/some_truisms.xml +++ presentations/slides/hpp/some_truisms.xml <slide title="Some Truisms"> <blurb>Some Truisms</blurb> <blurb>Ahmdahl?s Law</blurb> <blurb>80/20 rule</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/sqlopt1.xml +++ presentations/slides/hpp/sqlopt1.xml <slide title="SQL Optimization"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb> </blurb> <blurb>Use SQL to ensure you only fetch the rows you are interested in.</blurb> <example filename="bad_sql1.php" fontsize="1.7em" /> </slide> Index: presentations/slides/hpp/sqlopt2.xml +++ presentations/slides/hpp/sqlopt2.xml <slide title="SQL Optimization"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb>Especially when querying tables with large fields, only select the columns you really need.</blurb> <example filename="bad_sql2.php" fontsize="1.7em" /> </slide> Index: presentations/slides/hpp/sqlopt3.xml +++ presentations/slides/hpp/sqlopt3.xml <slide title="Sometimes Greed is Good"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">If you are going to use the majority of columns in a table on an average lifetime, especially the larger fields, pre-fetching all the fields is preferable to going back for seconds.</blurb> </slide> Index: presentations/slides/hpp/sqlopt4.xml +++ presentations/slides/hpp/sqlopt4.xml <slide title="In Conclusione"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <list fontsize="3.5em"> <bullet>Keep DB Logic in the DB</bullet> <bullet>Ordering</bullet> <bullet>Conditionals</bullet> <bullet>Limit return sets</bullet> </list> </slide> Index: presentations/slides/hpp/summarization1.sql +++ presentations/slides/hpp/summarization1.sql SELECT count(*) FROM users WHERE type='member' Index: presentations/slides/hpp/summarization2.sql +++ presentations/slides/hpp/summarization2.sql SELECT value FROM summaries WHERE name='member_value' Index: presentations/slides/hpp/summarization_example.xml +++ presentations/slides/hpp/summarization_example.xml <slide title="Summarization Example"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb fontsize="3.2em">Instead of calling</blurb> <blurb> </blurb> <example type="sql" fontsize="1.8em" filename="summarization1.sql" /> <blurb fontsize="3.2em">If you frequently need that count, try storing the count in a separate table</blurb> <example fontsize="1.8em" type="sql" filename="summarization2.sql" /> <blurb fontsize="3.2em">Keep this value current with either a trigger, a co-executed statement, or via an external job (if some delay is acceptable)</blurb> </slide> Index: presentations/slides/hpp/summarizations.xml +++ presentations/slides/hpp/summarizations.xml <slide title="Summarizations"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em">Frequently accessed sums, counts, and other miscellaneous calculations from a database can be pre-calculated and stored in a summary table.</blurb> </slide> Index: presentations/slides/hpp/sys_ob.xml +++ presentations/slides/hpp/sys_ob.xml <slide title="Output Buffering"> <image filename="10000000000000610000006B74D8AABB.jpg" align="right"/> <image title="Without Output Buffering" marginleft="2.0em" align="center" filename="wout_buff.png" /> <blurb> </blurb> <image title="With Output Buffering" marginleft="2.0em" align="center" filename="10000000000001D40000011AC4E008B1.png" /> </slide> Index: presentations/slides/hpp/targetting_your_efforts.xml +++ presentations/slides/hpp/targetting_your_efforts.xml <slide title="Targetting Your Efforts"> <blurb>Targetting Your Efforts</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/textstatistics_example.xml +++ presentations/slides/hpp/textstatistics_example.xml <slide title="Text_Statistics Example"> <blurb>Text_Statistics Example</blurb> <blurb>Cache the syllable counts for words when text parsing a document.</blurb> <image filename="10000000000000690000004538A678CE.jpg" /> </slide> Index: presentations/slides/hpp/third.php +++ presentations/slides/hpp/third.php <?php require_once "Cache_File.inc"; $cache = new Cache_File("third.html", 10); $cache->cachedir = "./"; // ... ?> Index: presentations/slides/hpp/titlepage.xml +++ presentations/slides/hpp/titlepage.xml <slide title="Welcome"> <blurb><![CDATA[<br/>]]></blurb> <blurb align="center" fontsize="6.0em">High Performance PHP</blurb> <blurb align="center" fontsize="4.0em">International PHP Conference, Amsterdam</blurb> <blurb align="center">May 7, 2003</blurb> <link align="center" leader="George Schlossnagle, " href="mailto:george@omniti.com" text="george@omniti.com"/> <link align="center" leader="Sterling Hughes, " href="mailto:sterling@php.net" text="sterling@php.net"/> </slide> Index: presentations/slides/hpp/tools_for_profiling.xml +++ presentations/slides/hpp/tools_for_profiling.xml <slide title="Tools For Profiling"> <blurb>Tools For Profiling</blurb> <blurb>DBG </blurb> <blurb>(http://dd.cron.ru/dbg/)</blurb> <blurb>APD </blurb> <blurb>(PECL)</blurb> <blurb>Xdebug (http://xdebug.derickrethans.nl/)</blurb> <image filename="100000000000005C0000005C29D61F11.jpg" /> </slide> Index: presentations/slides/hpp/total_page_caching.xml +++ presentations/slides/hpp/total_page_caching.xml <slide title="Total Page Caching"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/>]]></blurb> <image filename="100000000000014E000000CECE055B08.png" align="center"/> </slide> Index: presentations/slides/hpp/what_caching.xml +++ presentations/slides/hpp/what_caching.xml <slide title="What Caching Is"> <image filename="10000000000000690000004538A678CE.jpg" align="right"/> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb align="center" fontsize="3.5em">Caching is the recognition and exploitation of the fact that most "dynamic" data does not change every time you request it.</blurb> </slide> Index: presentations/slides/hpp/what_perf.xml +++ presentations/slides/hpp/what_perf.xml <slide title="What is Performance?"> <blurb><![CDATA[<br/><br/><br/><br/>]]></blurb> <blurb align="center" fontsize="3.5em">Ensuring that your application works correctly within required time constraints.</blurb> </slide> Index: presentations/slides/hpp/when_optimize.xml +++ presentations/slides/hpp/when_optimize.xml <slide title="When To Optimize?"> <blurb><![CDATA[<br/><br/><br/>]]></blurb> <blurb fontsize="3.5em" align="center">~Premature Optimzation Is The Root of All Evil.~</blurb> <blurb marginleft="1.0em" align="center">- Donalid E. Knuth</blurb> </slide>