cvs: presentations / vankey05.xml /slides/intro conf.xml dumb.xml input_filter.xml input_filter2.xml new_bench2.xml overflows.xml php5q1.xml
php5q2.xml poll1.xml spoon.jpg tech_bench1.xml tech_bench1a.xml tech_bench1pdf.xml tech_bench2.xml tech_bench4.xml tech_bench5.xml tech_bench6.xml
tech_bench7.xml tech_bench8.xml tech_benchapc1.xml tech_benchminit.xml worries.xml

From: Date: Fri, 14 Jan 2005 16:12:15 +0000
Subject: cvs: presentations / vankey05.xml /slides/intro conf.xml dumb.xml input_filter.xml input_filter2.xml new_bench2.xml overflows.xml php5q1.xml
php5q2.xml poll1.xml spoon.jpg tech_bench1.xml tech_bench1a.xml tech_bench1pdf.xml tech_bench2.xml tech_bench4.xml tech_bench5.xml tech_bench6.xml
tech_bench7.xml tech_bench8.xml tech_benchapc1.xml tech_benchminit.xml worries.xml
Groups: php.pres 
Request: Send a blank email to pres+get-1088@lists.php.net to get a copy of this message
rasmus Fri Jan 14 11:12:15 2005 EDT Added files: /presentations vankey05.xml /presentations/slides/intro conf.xml dumb.xml input_filter2.xml overflows.xml php5q1.xml php5q2.xml spoon.jpg tech_bench1.xml tech_bench1a.xml tech_bench1pdf.xml tech_bench2.xml tech_bench4.xml tech_bench5.xml tech_bench6.xml tech_bench7.xml tech_bench8.xml tech_benchapc1.xml tech_benchminit.xml worries.xml Modified files: /presentations/slides/intro input_filter.xml new_bench2.xml poll1.xml Log: Vancouver talk

http://cvs.php.net/diff.php/presentations/slides/intro/input_filter.xml?r1=1.2&r2=1.3&ty=u Index: presentations/slides/intro/input_filter.xml diff -u presentations/slides/intro/input_filter.xml:1.2 presentations/slides/intro/input_filter.xml:1.3 --- presentations/slides/intro/input_filter.xml:1.2 Tue Oct 26 13:53:02 2004 +++ presentations/slides/intro/input_filter.xml Fri Jan 14 11:12:14 2005 @@ -1,4 +1,4 @@ -<slide title="Input Filtering"> +<slide title="Input Filtering - Current"> <blurb> Security in a web application boils down to always checking any user-supplied input data. http://cvs.php.net/diff.php/presentations/slides/intro/new_bench2.xml?r1=1.1&r2=1.2&ty=u Index: presentations/slides/intro/new_bench2.xml diff -u presentations/slides/intro/new_bench2.xml:1.1 presentations/slides/intro/new_bench2.xml:1.2 --- presentations/slides/intro/new_bench2.xml:1.1 Wed Sep 22 15:15:35 2004 +++ presentations/slides/intro/new_bench2.xml Fri Jan 14 11:12:14 2005 @@ -58,8 +58,11 @@ </example> <example type="shell"> -[httpd.conf] +[Apache-1 httpd.conf] LoadModule gzip_module lib/apache/mod_gzip.so + +[Apache-2 httpd.conf] +LoadModule deflate_module lib/apache/mod_deflate.so </example> </slide> http://cvs.php.net/diff.php/presentations/slides/intro/poll1.xml?r1=1.1&r2=1.2&ty=u Index: presentations/slides/intro/poll1.xml diff -u presentations/slides/intro/poll1.xml:1.1 presentations/slides/intro/poll1.xml:1.2 --- presentations/slides/intro/poll1.xml:1.1 Wed Sep 22 15:15:35 2004 +++ presentations/slides/intro/poll1.xml Fri Jan 14 11:12:14 2005 @@ -16,7 +16,7 @@ <example title="Poll Template"><![CDATA[<?php start_poll(1); -$os = array("FreeBSD", "Linux","OSX", "Windows", "Other"); +$os = array("FreeBSD","Linux","OSX","Windows","Other"); ?> <p class="purpose"> Please answer a couple of questions for us. http://cvs.php.net/co.php/presentations/vankey05.xml?r=1.1&p=1 Index: presentations/vankey05.xml +++ presentations/vankey05.xml <presentation template="php2" navmode="html" titlecolor="#1111aa" navbarbackground="url(images/trans-ffffff.png)" logo1="images/php-med-trans-light.gif" titlesize="2em" navbarheight="4.1em" > <!-- 60 Minutes PHP has become amazingly popular due to its simple pragmatic approach to solving the web problem. Sometimes we forget some of the complexities that are inherent to any web application. In this talk Rasmus will give a brief overview of the new unified XML implementation in PHP5 which brings PHP's pragmatism to XML handling followed by a step-by-step approach to designing, implementing, securing and optimizing your PHP code. --> <topic>PHP</topic> <title>Pragmatic PHP</title> <event>PHP West</event> <location>Vancouver</location> <date>January 14, 2005</date> <speaker>Rasmus Lerdorf</speaker> <email>rasmus@php.net</email> <url>http://talks.php.net/vankey05</url> <slide>slides/intro/titlepage.xml</slide> <slide>slides/intro/problem_solving.xml</slide> <slide>slides/intro/php5q2.xml</slide> <slide>slides/intro/worries.xml</slide> <slide>slides/intro/overflows.xml</slide> <slide>slides/intro/dumb.xml</slide> <slide>slides/intro/input_filter.xml</slide> <slide>slides/intro/input_filter2.xml</slide> <!-- <slide>slides/intro/conf.xml</slide> --> <!-- Security Concerns Input Filtering Solution? Performance Considerations - handling constants and server variables - prefer-non-pic - syscalls --> <slide>slides/intro/tortech_goals.xml</slide> <chapter title="Design"> <slide>slides/intro/design.xml</slide> <slide>slides/intro/urlapi.xml</slide> <slide>slides/intro/pi.xml</slide> <!-- <slide>slides/intro/errdoc.xml</slide> --> <slide>slides/intro/file_layout.xml</slide> <slide>slides/intro/app_arch.xml</slide> </chapter> <chapter title="Implement"> <slide>slides/intro/poll1.xml</slide> <slide>slides/intro/poll2.xml</slide> <slide>slides/intro/poll3.xml</slide> </chapter> <chapter title="Performance"> <slide>slides/intro/php_tuning1.xml</slide> <slide>slides/intro/php_opcode_caches.xml</slide> <slide>slides/intro/php_opcode_caches-split.xml</slide> <slide>slides/intro/new_apc.xml</slide> <slide>slides/intro/php_opcode_caches3.xml</slide> <slide>slides/intro/tech_bench1.xml</slide> <slide>slides/intro/tech_bench1a.xml</slide> <slide>slides/intro/tech_bench2.xml</slide> <slide>slides/intro/new_bench3.xml</slide> <slide>slides/intro/php_profiling.xml</slide> <slide>slides/intro/new_apc.xml</slide> <slide>slides/intro/tech_benchapc1.xml</slide> <slide>slides/intro/tech_benchminit.xml</slide> <slide>slides/intro/tech_bench5.xml</slide> <slide>slides/intro/tech_bench6.xml</slide> <slide>slides/intro/tech_bench7.xml</slide> <slide>slides/intro/tech_bench8.xml</slide> <slide>slides/intro/tech_bench4.xml</slide> <slide>slides/intro/repl1.xml</slide> <slide>slides/intro/repl3.xml</slide> <slide>slides/intro/stop.xml</slide> </chapter> <slide>slides/intro/resources.xml</slide> </presentation> http://cvs.php.net/co.php/presentations/slides/intro/conf.xml?r=1.1&p=1 Index: presentations/slides/intro/conf.xml +++ presentations/slides/intro/conf.xml <slide title="PHP Config"> <blurb> A little-known PHP build option lets you have multiple .ini files which can be very handy. </blurb> <example><![CDATA[--with-config-file-scan-dir=/etc/php]]></example> <example title="Some Suggestions" fontsize="1.8em"><![CDATA[include_path = /usr/local/lib/php:. display_errors = Off max_execution_time = 30 post_max_size = 8M file_uploads = Off safe_mode = Off enable_dl = Off display_startup_errors = Off log_errors = On error_reporting = E_ALL html_errors = Off track_errors = Off magic_quotes_gpc = Off magic_quotes_runtime = Off magic_quotes_sybase = Off expose_php = Off allow_url_fopen = Off register_globals = Off register_argc_argv = On variables_order = "GPC" gpc_order = "GPC" extension = input_filter.so ]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/dumb.xml?r=1.1&p=1 Index: presentations/slides/intro/dumb.xml +++ presentations/slides/intro/dumb.xml <slide title="Direct Attacks"> <blurb title="Dumb things" /> <blurb> Don't do dumb things! </blurb> <example><![CDATA[<?php system($user_data); ?>]]></example> <example><![CDATA[<?php include "$path/$user_data"; ?>]]></example> <example><![CDATA[<?php eval($user_data); ?>]]></example> <blurb title="Others"> preg_replace with /e option, exec(), popen(), passthru, and backticks `` </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/intro/input_filter2.xml?r=1.1&p=1 Index: presentations/slides/intro/input_filter2.xml +++ presentations/slides/intro/input_filter2.xml <slide title="Input Filtering - Future"> <image filename="spoon.jpg" align="right" /> <break lines="7" /> <blurb> Nobody is going to use that hook! People don't seem to understand how to filter their input. We'll need to spoonfeed again. </blurb> <break lines="6" /> <example title="API?"><![CDATA[<?php $name = pfilt(POST, 'name'); /* Default filter */ $age = pfilt(POST, 'age', PFILT_INTEGER); $addr = pfilt(POST, 'addr', PFILT_TEXT, 'UTF-8'); ?>]]></example> <example title="Config"><![CDATA[input_filter.default = PFILT_TEXT ]]></example> <example title="Strip or Escape?"><![CDATA[abc;123{def} abc 123 def abc%3B123%7Bdef%7D]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/overflows.xml?r=1.1&p=1 Index: presentations/slides/intro/overflows.xml +++ presentations/slides/intro/overflows.xml <slide title="Direct Attacks"> <blurb title="Overflows" /> <blurb> It is a bit difficult to talk about buffer overflows because we tend to fix them as soon as we discover them. But some overflows we have hit in the past include problems in: </blurb> <list> <bullet>serialize/unserialize</bullet> <bullet>pack/unpack</bullet> <bullet>jpg algorithm</bullet> <bullet>exif header field overflows</bullet> <bullet>static buffer in getMimeHeaders() in ycore++</bullet> </list> <blurb> There is also a current issue in most libc realpath() calls that is troublesome. </blurb> <example title="realpath man page" fontsize="1.4em"><![CDATA[REALPATH(3) FreeBSD Library Functions Manual REALPATH(3) NAME realpath - returns the canonicalized absolute pathname LIBRARY Standard C Library (libc, -lc) SYNOPSIS #include <sys/param.h> #include <stdlib.h> char * realpath(const char *pathname, char resolved_path[MAXPATHLEN]); DESCRIPTION The realpath() function resolves all symbolic links, extra ``/'' charac- ters and references to /./ and /../ in pathname, and copies the resulting absolute pathname into the memory referenced by resolved_path. The resolved_path argument must refer to a buffer capable of storing at least MAXPATHLEN characters. The realpath() function will resolve both absolute and relative paths and return the absolute pathname corresponding to pathname. All but the last component of pathname must exist when realpath() is called. RETURN VALUES The realpath() function returns resolved_path on success. If an error occurs, realpath() returns NULL, and resolved_path contains the pathname which caused the problem. ERRORS The function realpath() may fail and set the external variable errno for any of the errors specified for the library functions chdir(2), close(2), fchdir(2), lstat(2), open(2), readlink(2) and getcwd(3). CAVEATS This implementation of realpath() differs slightly from the Solaris implementation. The 4.4BSD version always returns absolute pathnames, whereas the Solaris implementation will, under certain circumstances, return a relative resolved_path when given a relative pathname. SEE ALSO getcwd(3) HISTORY The realpath() function call first appeared in 4.4BSD. ]]></example> <example title="Imagine this C code" fontsize="1.8em"><![CDATA[ #define DOCROOT "/home/y/share/htdocs" #define SCRIPT "my_script" int len = sizeof(DOCROOT) + sizeof(SCRIPT); + strlen(user_input); char *path = (char *)malloc(len+1); char safe_path[MAXPATHLEN]; snprintf(path, len, "%s/%s/%s", DOCROOT, user_input, SCRIPT); if(realpath(path, safe_path)) { DIR *dir = opendir(safe_path); ... } ]]></example> <example title="Problem code in FreeBSD realpath.c"><![CDATA[... resolved_len = strlcat(resolved, next_token, PATH_MAX); if (resolved_len >= PATH_MAX) { errno = ENAMETOOLONG; return (NULL); }.... ]]></example> <blurb> It makes sure we never get a string back longer than PATH_MAX, but the silent strlcat truncation of the tokenized source path is a big problem! </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/intro/php5q1.xml?r=1.1&p=1 Index: presentations/slides/intro/php5q1.xml +++ presentations/slides/intro/php5q1.xml <slide title="PHP5"> <example title="Objects Are References" result="0"><![CDATA[<?php $a = new my_class; $b = clone $a; ?>]]></example> <example title="New constructor/destructor naming" result="0"><![CDATA[<?php class my_class { function __construct() { echo "Constructor"; } function __destruct() { echo "Destructor"; } } ?>]]></example> <example title="PPP" result="0"><![CDATA[<?php class my_class { public $a; protected $b; private $c; } ?>]]></example> <example title="Overloaded Properties and Methods" result="0"><![CDATA[<?php class my_class { function __set($name, $value) { } function __get($name) { } function __call($name, $args) { } } ?>]]></example> <example title="Exceptions" result="0"><![CDATA[<?php try { mysql_connect('localhost'); mysql_select_db('game'); $r = mysql_query('SELECT * FROM news'); } catch (Exception $e) { /* Do recovery */ exit(); } ?>]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/php5q2.xml?r=1.1&p=1 Index: presentations/slides/intro/php5q2.xml +++ presentations/slides/intro/php5q2.xml <slide title="PHP5 XML"> <example title="All XML handling based on libxml2" result="0"><![CDATA[<?php $dom = new domDocument; $dom->load('data.xml'); ?>]]></example> <example title="XSL" result="0"><![CDATA[<?php $domxsl = domDocument::load('stylesheet.xsl'); $proc = new xsltProcessor; $proc->importStyleSheet($domxsl); echo $proc->transformToXML($dom); ?>]]></example> <example title="XPath" result="0"><![CDATA[<?php $ctx = new domXPath($dom); $result = $ctx->query( '/breakfast_menu/food[@itemno > 3]/price/text()'); foreach($result as $node) { echo $node->nodeValue."<br />\n"; } ?>]]></example> <example title="SimpleXML" result="0"><![CDATA[<?php $menu = simplexml_load_file('menu.xml'); foreach ($menu->food as $item) { echo "{$item->price}\t{$item->name}<br />\n"; } ?>]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench1.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench1.xml +++ presentations/slides/intro/tech_bench1.xml <slide title="Benchmarking"> <blurb> Let's have a look at how we might benchmark and subsequently tune a PHP server. I use %http_load% from acme.com to do the actual testing. </blurb> <example title="This is our benchmark script" fontsize="1.5em" filename="tb/newbench_main.php"/> <example title="bench_include1.inc" fontsize="1.5em" filename="tb/bench_config.inc"/> <example title="bench_include1.inc" fontsize="1.5em" filename="tb/bench_include1.inc"/> <example title="bench_include2.inc" fontsize="1.5em" filename="tb/bench_include2.inc"/> <example title="menu.xml" fontsize="1.5em" type="xml" filename="menu.xml"/> <example title="menu.xsl" fontsize="1.5em" type="xsl" filename="menu.xsl"/> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench1a.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench1a.xml +++ presentations/slides/intro/tech_bench1a.xml <slide title="Output"> <break lines="1" /> <example hide="1" result="1" rfontsize="1em" filename="tb/newbench_main.php"/> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench1pdf.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench1pdf.xml +++ presentations/slides/intro/tech_bench1pdf.xml <slide title="Benchmarking"> <blurb> Let's have a look at how we might benchmark and subsequently tune a PHP server. I use %http_load% from acme.com to do the actual testing. </blurb> <example title="This is our benchmark script" fontsize="1.5em"><![CDATA[ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>Simple PHP Benchmark</title></head> <body> <h1>String Manipulation</h1> <p> <?php $str = 'This is just a silly benchmark that doesn\'t do anything useful.'; $str .= 'Here we are just uppercasing the first two characters of every word '; $str .= 'in this long string'; $parts = explode(' ',$str); foreach($parts as $part) { $new[] = strtoupper(substr($part,0,2)).substr($part,2); } echo implode(' ',$new); ?> </p> <p> <h1>Including 3 files</h1> <p> <?php @chdir("presentations/slides/yahoo/tb"); include './bench_config.inc'; include './bench_include1.inc'; include './bench_include2.inc'; ?> </p> <h1>for-loop and calling a function many times</h1> <p> <?php $a = range(1,200); $b = range(200,1); for($i=0; $i<200; $i++) { echo foo($a[$i],$b[$i]); } ?> </p> <h1>Define and Instantiate an object and call some methods</h2> <p> <?php class test_class { var $test_var1; var $test_var2; var $test_var3; var $test_var4; function test_class() { $this->test_var1 = 111; $this->test_var2 = 222; $this->test_var3 = 333; $this->test_var4 = 444; } function get_props_sum() { return $this->test_var1 + $this->test_var2 + $this->test_var3 + $this->test_var4; } function set_var1($value) { $this->test_var1 = $value; echo "test_var1 property set to $value<br />\n"; return true; } function set_var2($value) { $this->test_var2 = $value; echo "test_var2 property set to $value<br />\n"; return true; } function set_var3($value) { $this->test_var3 = $value; echo "test_var3 property set to $value<br />\n"; return true; } function set_var4($value) { $this->test_var4 = $value; echo "test_var4 property set to $value<br />\n"; return true; } function disp() { echo "<pre>"; print_r($this); echo "</pre>"; } } $obj = new test_class(); echo $obj->get_props_sum(); $obj->set_var1('test1'); $obj->set_var2(123); $obj->set_var3($a); /* Array from previous test */ $obj->set_var4(array(1,2,3,4,5,6,7,8,9)); $obj->disp(); ?> <h1>And finally a bit of XML and XSLT</h1> <?php $xml = domxml_open_file('menu.xml'); $xsl = domxml_xslt_stylesheet_file('menu.xsl'); $out = $xsl->process($xml); echo $out->dump_mem(); ?> </p> </body> </html>]]></example> <example title="bench_include1.inc" fontsize="1.5em"><![CDATA[ <h1>Some defines</h1> <?php define("MYMOD_VERSION","1.234-alpha"); for($i=0; $i<1000; $i++) { define(sprintf("MY_CONST_%04d",$i),$i); } echo MYMOD_VERSION; echo MY_CONST_0001; echo MY_CONST_0002; echo MY_CONST_0003; echo MY_CONST_0004; echo MY_CONST_0005; echo MY_CONST_0006; echo MY_CONST_0007; echo MY_CONST_0008; echo MY_CONST_0009; echo MY_CONST_0010; echo MY_CONST_0011; echo MY_CONST_0012; echo MY_CONST_0012; echo MY_CONST_0013; echo MY_CONST_0014; echo MY_CONST_0015; echo MY_CONST_0016; echo MY_CONST_0017; echo MY_CONST_0018; echo MY_CONST_0019; echo MY_CONST_0020; ?>]]></example> <example title="bench_include1.inc" fontsize="1.5em"><![CDATA[<?php function foo($arg1, $arg2) { if($arg1>$arg2) return $arg1; elseif($arg1<$arg2) return $arg2; else return 'xxx'; } ?>]]></example> <example title="bench_include2.inc" fontsize="1.5em"><![CDATA[ This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> This is just a bunch of plain text in an include file.<br /> ]]></example> <example title="menu.xml" fontsize="1.5em" type="xml"><![CDATA[<?xml version="1.0" encoding="ISO-8859-1"?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description>two of our famous Belgian Waffles with plenty of real maple syrup</description> <calories>650</calories> </food> <food> <name>Strawberry Belgian Waffles</name> <price>$7.95</price> <description>light Belgian waffles covered with strawberries and whipped cream</description> <calories>900</calories> </food> <food> <name>Berry-Berry Belgian Waffles</name> <price>$8.95</price> <description>light Belgian waffles covered with an assortment of fresh berries and whipped cream</description> <calories>900</calories> </food> <food> <name>French Toast</name> <price>$4.50</price> <description>thick slices made from our homemade sourdough bread</description> <calories>600</calories> </food> <food> <name>Homestyle Breakfast</name> <price>$6.95</price> <description>two eggs, bacon or sausage, toast, and our ever-popular hash browns</description> <calories>950</calories> </food> </breakfast_menu> ]]></example> <example title="menu.xsl" fontsize="1.5em" type="xsl"><![CDATA[<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict"> <xsl:template match="/"> <xsl:for-each select="breakfast_menu/food"> <div style="background-color:teal;color:white;padding:4px"> <span style="font-weight:bold;color:white"> <xsl:value-of select="name"/> </span> - <xsl:value-of select="price"/> </div> <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> <xsl:value-of select="description"/> <span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per serving) </span> </div> </xsl:for-each> </xsl:template> </xsl:stylesheet> ]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench2.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench2.xml +++ presentations/slides/intro/tech_bench2.xml <slide title="Benchmarking Results"> <example type="shell" title="An http_load run" fontsize="1.5em"> 5000 fetches, 5 max parallel, 5.1645e+07 bytes, in 74.0229 seconds 10329 mean bytes/connection *67.5466* fetches/sec, 697689 bytes/sec msecs/connect: 0.219601 mean, 1.106 max, 0.171 min msecs/first-response: 72.1792 mean, 1209.1 max, 14.354 min HTTP response codes: code 200 -- 5000 </example> <blurb>Whenever you do any sort of load testing, you need look beyond just the raw numbers and have a look at what your server is actually doing. Use %vmstat%: </blurb> <example type="shell" title="Base PHP Load" fontsize="1.5em" marginleft="1em" marginright="0em"> 6:33am riddler:~> vmstat 1 procs memory page disks faults cpu r b w avm fre flt re pi po fr sr ad0 ad2 in sy cs us sy id 5 1 0 175880 59292 491 0 0 0 408 0 0 0 858 7725 128 90 10 0 5 1 0 175844 59296 481 0 0 0 414 0 0 6 869 7714 133 85 15 0 5 1 0 175880 59256 492 0 0 0 414 0 0 0 873 7798 114 82 18 0 5 1 0 175880 59248 472 0 0 0 402 0 2 1 848 7599 146 89 11 0 5 1 0 175880 59232 479 0 0 0 408 0 0 0 858 7649 130 89 11 0 5 1 0 176232 59244 479 0 0 0 414 0 1 0 863 7673 144 82 18 0 5 1 0 171444 59256 790 0 0 0 672 0 3 0 826 7770 158 91 9 0 5 1 0 171480 59216 478 0 0 0 402 0 0 0 843 7626 139 89 11 0 5 1 0 171444 59224 480 0 0 0 414 0 0 0 862 7673 124 90 10 0 5 1 0 171516 59168 491 0 0 0 408 0 0 0 846 7699 147 87 13 0 </example> <blurb> Our benchmark test was deliberately designed to have quite a bit of PHP processing and not a whole lot of output. 10k is somewhat small for a web page. If instead we have a whole lot of output, chances are we will be io-bound instead of cpu-bound. If you are io-bound, there is little sense in optimizing at the PHP level. </blurb> <example type="shell" title="Evidence of an io-bound test" fontsize="1.5em" marginleft="1em" marginright="0em"> procs memory page disks faults cpu r b w avm fre flt re pi po fr sr ad0 ac0 in sy cs us sy id 4 0 0 132860 15724 1033 0 0 0 0 0 0 0 4457 954 3704 2 25 74 5 0 0 132860 15724 1009 0 0 0 0 0 0 0 4436 714 3597 3 24 73 6 0 0 132860 15716 980 0 0 0 0 0 0 0 4446 925 3603 5 23 72 2 0 0 132860 15716 1028 0 0 0 0 0 6 0 4514 720 3696 2 24 73 3 0 0 132472 15716 1018 0 0 0 0 0 2 0 4501 946 3673 2 22 76 4 0 0 132472 15716 1039 0 0 0 0 0 0 0 4565 737 3718 2 26 73 3 0 0 132472 15708 1010 0 0 0 0 0 2 0 4498 938 3639 2 24 75 2 0 0 132472 15708 1012 0 0 0 0 0 0 0 4543 730 3665 5 25 70 </example> <example type="shell" title="Things to try if you are io-bound"> [php.ini] output_handler = ob_gzhandler </example> <example type="shell"> [Apache-1 httpd.conf] LoadModule gzip_module lib/apache/mod_gzip.so [Apache-2 httpd.conf] LoadModule deflate_module lib/apache/mod_deflate.so </example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench4.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench4.xml +++ presentations/slides/intro/tech_bench4.xml <slide title="Benchmarking Results"> <break lines="5" /> <example type="shell"> 67 requests/sec Base Optimized PHP 4.3 75 requests/sec Add APC 108 requests/sec APC+apc_load_constants() 139 requests/sec APC+MINIT Constants 153 requests/sec APC+MINIT+FastXSL 186 requests/sec APC+MINIT+Cheat 188 requests/sec APC+MINIT+Cheat+OO in C 188 requests/sec APC+MINIT+Cheat+OO in C+myupper </example> <break lines="2" /> <blurb fontsize="8em" align="center"> STOP! </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench5.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench5.xml +++ presentations/slides/intro/tech_bench5.xml <slide title="Speed Up XSLT"> <example title="Replace DomXML"><![CDATA[<?php $xml = domxml_open_file('menu.xml'); $xsl = domxml_xslt_stylesheet_file('menu.xsl'); $out = $xsl->process($xml); echo $out->dump_mem(); ?>]]></example> <example title="With FastXSL"><![CDATA[<?php $xml = fastxsl_xml_parsefile('menu.xml'); $res = fastxsl_prmcache_transform('menu.xsl',$xml); echo fastxsl_prmcache_tostring('menu.xsl',$res); ?>]]></example> <break lines="1" /> <example type="shell" title="FastXSL" fontsize="1.5em"> 5000 fetches, 5 max parallel, 5.16e+07 bytes, in 32.6279 seconds 10320 mean bytes/connection *153.243* fetches/sec, 1.58147e+06 bytes/sec msecs/connect: 0.230745 mean, 1.294 max, 0.174 min msecs/first-response: 30.8827 mean, 845.914 max, 6.218 min HTTP response codes: code 200 -- 5000 </example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench6.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench6.xml +++ presentations/slides/intro/tech_bench6.xml <slide title="Cheat"> <blurb> And when you can't win the fight fairly, cheat! </blurb> <example title="Who needs XSL anyway?"><![CDATA[<?php $xml = domxml_open_file('menu.xml'); $xsl = domxml_xslt_stylesheet_file('menu.xsl'); $out = $xsl->process($xml); echo $out->dump_mem(); ?>]]></example> <example title="Cheat!" fontsize="1.8em"><![CDATA[<?php $menu = apc_fetch('menu'); if(!$menu) { $dom = domxml_open_file('menu.xml'); $root = $dom->document_element(); $node = $root->first_child(); $i=0; while($node) { $subnode = $node->first_child(); while($subnode) { if(isset($subnode->tagname)) { $menu[$i][$subnode->tagname] = $subnode->get_content(); } $subnode = $subnode->next_sibling(); } $i++; $node = $node->next_sibling(); } apc_store('menu',$menu); } foreach($menu as $item) { echo <<<EOT <div style="background-color:teal;color:white;padding:4px"> <span style="font-weight:bold;color:white">$item[name]</span> - $item[price] </div> <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> $item[description] <span style="font-style:italic">($item[calories] calories per serving)</span> </div> EOT; } ?>]]></example> <break lines="1" /> <example type="shell" title="CheatXSL" fontsize="1.5em"> 5000 fetches, 5 max parallel, 4.8985e+07 bytes, in 26.8186 seconds 9797 mean bytes/connection *186.438* fetches/sec, 1.82653e+06 bytes/sec msecs/connect: 0.229313 mean, 3.551 max, 0.175 min msecs/first-response: 25.2418 mean, 639.892 max, 5.021 min HTTP response codes: code 200 -- 5000 </example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench7.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench7.xml +++ presentations/slides/intro/tech_bench7.xml <slide title="Move OO to Extension"> <example title="test_class"><![CDATA[<?php class test_class { var $test_var1; var $test_var2; var $test_var3; var $test_var4; function test_class() { $this->test_var1 = 111; $this->test_var2 = 222; $this->test_var3 = 333; $this->test_var4 = 444; } function get_props_sum() { return $this->test_var1 + $this->test_var2 + $this->test_var3 + $this->test_var4; } ... ?>]]></example> <example title="After" fontsize="1.8em"><![CDATA[<?php class my_test_class extends test_class { function set_var1($value) { $this->test_var1 = $value; echo "test_var1 property set to $value<br />\n"; return true; } ... ?>]]></example> <break lines="1" /> <example fontsize="1.5em"><![CDATA[static zend_class_entry *test_class_entry_ptr; static zend_function_entry php_test_class_functions[] = { PHP_FE(test_class, NULL) PHP_FE(get_props_sum, NULL) {NULL, NULL, NULL} }; PHP_MINIT_FUNCTION(mymod) { int i; char s[] = "MY_CONST_XXXX"; char num[] = "0000"; zend_class_entry test_class_entry; INIT_CLASS_ENTRY(test_class_entry, "test_class", php_test_class_functions); test_class_entry_ptr = zend_register_internal_class(&test_class_entry); REGISTER_STRING_CONSTANT("MYMOD_VERSION", "1.234-alpha", CONST_CS | CONST_PERSISTENT); for(i=0; i<1000; i++) { sprintf(s+9,"%04d",i); REGISTER_LONG_CONSTANT(s, i, CONST_CS | CONST_PERSISTENT); } return SUCCESS; } PHP_FUNCTION(test_class) { add_property_long(this_ptr, "test_var1", 111); add_property_long(this_ptr, "test_var2", 222); add_property_long(this_ptr, "test_var3", 333); add_property_long(this_ptr, "test_var4", 444); } PHP_FUNCTION(get_props_sum) { long sum = 0L; zval **tmp; zend_hash_find(HASH_OF(this_ptr), "test_var1", sizeof("test_var1"), (void **)&tmp); sum += Z_LVAL_PP(tmp); zend_hash_find(HASH_OF(this_ptr), "test_var2", sizeof("test_var2"), (void **)&tmp); sum += Z_LVAL_PP(tmp); zend_hash_find(HASH_OF(this_ptr), "test_var3", sizeof("test_var3"), (void **)&tmp); sum += Z_LVAL_PP(tmp); zend_hash_find(HASH_OF(this_ptr), "test_var4", sizeof("test_var4"), (void **)&tmp); sum += Z_LVAL_PP(tmp); RETURN_LONG(sum); }]]></example> <example type="shell" title="test_class in C" fontsize="1.5em"> 5000 fetches, 5 max parallel, 4.9e+07 bytes, in 26.4851 seconds 9800 mean bytes/connection *188.786* fetches/sec, 1.8501e+06 bytes/sec msecs/connect: 0.227158 mean, 4.357 max, 0.171 min msecs/first-response: 24.9438 mean, 639.423 max, 4.976 min HTTP response codes: code 200 -- 5000 </example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_bench8.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_bench8.xml +++ presentations/slides/intro/tech_bench8.xml <slide title="String Manip to C"> <example title="Original"><![CDATA[<?php foreach($parts as $part) { $new[] = strtoupper(substr($part,0,2)).substr($part,2); } ?>]]></example> <example title="myupper()" fontsize="1.8em"><![CDATA[<?php foreach($parts as $part) { $new[] = myupper($part); } ?>]]></example> <break lines="1" /> <example fontsize="1.5em"><![CDATA[PHP_FUNCTION(myupper) { char *str; int strlen; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &strlen) == FAILURE) return; str[0] = toupper(str[0]); str[1] = toupper(str[1]); RETURN_STRINGL(str,strlen,1); }]]></example> <example type="shell" title="myupper()" fontsize="1.5em"> 5000 fetches, 5 max parallel, 4.9e+07 bytes, in 26.5051 seconds 9800 mean bytes/connection 188.643 fetches/sec, 1.8487e+06 bytes/sec msecs/connect: 0.22962 mean, 0.991 max, 0.166 min msecs/first-response: 24.9912 mean, 749.49 max, 4.939 min HTTP response codes: code 200 -- 5000 </example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_benchapc1.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_benchapc1.xml +++ presentations/slides/intro/tech_benchapc1.xml <slide title="Benchmarking Results"> <example type="shell" title="After adding APC" fontsize="1.5em"> 5000 fetches, 5 max parallel, 5.1645e+07 bytes, in 66.1261 seconds 10329 mean bytes/connection *75.6131* fetches/sec, 781008 bytes/sec msecs/connect: 0.21676 mean, 0.939 max, 0.174 min msecs/first-response: 64.1843 mean, 1074.19 max, 12.774 min HTTP response codes: code 200 -- 5000 </example> <example title="Using apc_load_constants()"><![CDATA[<?php if(!apc_load_constants('bench_constants')) { $constants = array("MYMOD_VERSION"=>"1.234-alpha"); for($i=0; $i<1000; $i++) { $constants[sprintf("MY_CONST_%04d", $i)] = $i; } apc_define_constants('bench_constants', $constants); } ?>]]></example> <example type="shell" title="With apc_load_constants()" fontsize="1.5em"> 5000 fetches, 5 max parallel, 5.1645e+07 bytes, in 46.0241 seconds 10329 mean bytes/connection *108.639* fetches/sec, 1.12213e+06 bytes/sec msecs/connect: 0.225471 mean, 0.938 max, 0.174 min msecs/first-response: 44.1477 mean, 805.834 max, 8.793 min HTTP response codes: code 200 -- 5000 </example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tech_benchminit.xml?r=1.1&p=1 Index: presentations/slides/intro/tech_benchminit.xml +++ presentations/slides/intro/tech_benchminit.xml <slide title="MINIT"> <blurb>apc_load_constants() is ok, but writing your own simple PHP extension and using the Module Init (MINIT) hook is much better</blurb> <example title="MINIT Constants" fontsize="1.5em"><![CDATA[PHP_MINIT_FUNCTION(mymod) { int i; char s[] = "MY_CONST_XXXX"; char num[] = "0000"; REGISTER_STRING_CONSTANT("MYMOD_VERSION", "1.234-alpha", CONST_CS | CONST_PERSISTENT); for(i=0; i<1000; i++) { sprintf(s+9,"%04d",i); REGISTER_LONG_CONSTANT(s, i, CONST_CS | CONST_PERSISTENT); } return SUCCESS; }?>]]></example> <example type="shell" title="Using MINIT Instead" fontsize="1.5em"> 5000 fetches, 5 max parallel, 5.1645e+07 bytes, in 35.9252 seconds 10329 mean bytes/connection *139.178* fetches/sec, 1.43757e+06 bytes/sec msecs/connect: 0.234849 mean, 7.323 max, 0.174 min msecs/first-response: 34.366 mean, 706.119 max, 6.764 min HTTP response codes: code 200 -- 5000 </example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/worries.xml?r=1.1&p=1 Index: presentations/slides/intro/worries.xml +++ presentations/slides/intro/worries.xml <slide title="Worries"> <break lines="2" /> <blurb align="center" fontsize="8em">Indirect Attacks</blurb> <blurb marginleft="5em" fontsize="5em">* XSS - Cross-site scripting attacks</blurb> <blurb marginleft="5em" fontsize="5em">* Spoofing</blurb> <blurb align="center" fontsize="8em">Direct Attacks</blurb> <blurb marginleft="5em" fontsize="5em">* Buffer Overflows</blurb> <blurb marginleft="5em" fontsize="5em">* Path tricks</blurb> <blurb marginleft="5em" fontsize="5em">* Application logic attacks</blurb> </slide>
« previous php.pres (#1088) next »