cvs: presentations / tortech04.xml /slides/extending ext13.xml /slides/intro design.xml file_layout.xml large.xml layers_a.xml layers_b.xml
new_apc.xml new_bench1.xml new_bench1a.xml new_bench2.xml new_bench3.xml new_bench4.xml new_bench5.xml php_opcode_caches3.xml poll1.xml poll2.xml
poll3.xml repl3.png repl3.xml tortech_goals.xml valgrind.xml whyphp.xml xdebug.xml

From: Date: Wed, 22 Sep 2004 19:15:36 +0000
Subject: cvs: presentations / tortech04.xml /slides/extending ext13.xml /slides/intro design.xml file_layout.xml large.xml layers_a.xml layers_b.xml
new_apc.xml new_bench1.xml new_bench1a.xml new_bench2.xml new_bench3.xml new_bench4.xml new_bench5.xml php_opcode_caches3.xml poll1.xml poll2.xml
poll3.xml repl3.png repl3.xml tortech_goals.xml valgrind.xml whyphp.xml xdebug.xml
Groups: php.pres 
Request: Send a blank email to pres+get-1063@lists.php.net to get a copy of this message
rasmus Wed Sep 22 15:15:36 2004 EDT Added files: /presentations tortech04.xml /presentations/slides/intro file_layout.xml layers_a.xml layers_b.xml new_apc.xml new_bench1.xml new_bench1a.xml new_bench2.xml new_bench3.xml new_bench4.xml new_bench5.xml poll1.xml poll2.xml poll3.xml repl3.png repl3.xml tortech_goals.xml Modified files: /presentations/slides/extending ext13.xml /presentations/slides/intro design.xml large.xml php_opcode_caches3.xml valgrind.xml whyphp.xml xdebug.xml Log: Toronto technical talk

http://cvs.php.net/diff.php/presentations/slides/extending/ext13.xml?r1=1.3&r2=1.4&ty=u Index: presentations/slides/extending/ext13.xml diff -u presentations/slides/extending/ext13.xml:1.3 presentations/slides/extending/ext13.xml:1.4 --- presentations/slides/extending/ext13.xml:1.3 Thu Oct 23 13:38:17 2003 +++ presentations/slides/extending/ext13.xml Wed Sep 22 15:15:35 2004 @@ -3,7 +3,7 @@ The simple types are returned using the following convenience macros: </blurb> -<example fontsize="1.8em" type="c"><![CDATA[#define RETVAL_RESOURCE(l) ZVAL_RESOURCE(return_value, l) +<example fontsize="1.6em" type="c"><![CDATA[#define RETVAL_RESOURCE(l) ZVAL_RESOURCE(return_value, l) #define RETVAL_BOOL(b) ZVAL_BOOL(return_value, b) #define RETVAL_NULL() ZVAL_NULL(return_value) #define RETVAL_LONG(l) ZVAL_LONG(return_value, l) http://cvs.php.net/diff.php/presentations/slides/intro/design.xml?r1=1.1&r2=1.2&ty=u Index: presentations/slides/intro/design.xml diff -u presentations/slides/intro/design.xml:1.1 presentations/slides/intro/design.xml:1.2 --- presentations/slides/intro/design.xml:1.1 Sat Apr 17 03:54:21 2004 +++ presentations/slides/intro/design.xml Wed Sep 22 15:15:35 2004 @@ -1,9 +1,19 @@ <slide title="Design"> -<list title="Considerations" fontsize="4em"> +<break lines="2" /> +<list title="Outside-in and Inside-out view" fontsize="4em"> +<bullet> What do outsiders (users) see looking in?</bullet> +<bullet> What do insiders (developers) see looking out?</bullet> +</list> +<break lines="2" /> +<list title="Outside-in" fontsize="4em"> <bullet>The URL - The API to your Web App</bullet> <bullet>User interface flow</bullet> +</list> +<break lines="2" /> +<list title="Inside-out" fontsize="4em"> <bullet>File Layout</bullet> <bullet>Separation of layout from business logic</bullet> <bullet>Server Architecture and Load Balancing</bullet> </list> + </slide> http://cvs.php.net/diff.php/presentations/slides/intro/large.xml?r1=1.1&r2=1.2&ty=u Index: presentations/slides/intro/large.xml diff -u presentations/slides/intro/large.xml:1.1 presentations/slides/intro/large.xml:1.2 --- presentations/slides/intro/large.xml:1.1 Thu Jun 24 09:07:07 2004 +++ presentations/slides/intro/large.xml Wed Sep 22 15:15:35 2004 @@ -12,5 +12,6 @@ <blurb>Merger of 24 Web Companies</blurb> <image filename="24.png" align="center" /> +<blurb>Make that 26 now with FareChase and MusicMatch</blurb> </slide> http://cvs.php.net/diff.php/presentations/slides/intro/php_opcode_caches3.xml?r1=1.2&r2=1.3&ty=u Index: presentations/slides/intro/php_opcode_caches3.xml diff -u presentations/slides/intro/php_opcode_caches3.xml:1.2 presentations/slides/intro/php_opcode_caches3.xml:1.3 --- presentations/slides/intro/php_opcode_caches3.xml:1.2 Sat Apr 17 10:50:13 2004 +++ presentations/slides/intro/php_opcode_caches3.xml Wed Sep 22 15:15:35 2004 @@ -1,6 +1,6 @@ <slide title="APC Stats"> -<example filename="apc.php" hide="1" result="1" type="iframe" iheight="1150"/> +<example filename="apc.php" marginleft="1em" marginright="0em" hide="1" result="1" type="iframe" iheight="1450"/> <blurb> </blurb> http://cvs.php.net/diff.php/presentations/slides/intro/valgrind.xml?r1=1.1&r2=1.2&ty=u Index: presentations/slides/intro/valgrind.xml diff -u presentations/slides/intro/valgrind.xml:1.1 presentations/slides/intro/valgrind.xml:1.2 --- presentations/slides/intro/valgrind.xml:1.1 Fri Mar 26 11:05:10 2004 +++ presentations/slides/intro/valgrind.xml Wed Sep 22 15:15:35 2004 @@ -11,4 +11,12 @@ Also make sure you use an atomic file deployment mechanism like *rsync* or *mv*. Never *tar* or *cp* files to their final destinations on a running production server. </blurb> +<blurb title="Beware of cache slams"> +When a file is modified on a busy server there is a race to compile and cache the +new file. This can put a drain on your server and its resources. Because APC uses +the device+inode as the hash, you can make use of that in your file update strategy. +Write new files to a temporary filename or perhaps a temporary directory, hit it once, +then rename it to its publically visible location. mtime does not change on a rename +as long as you are not moving it from one fs to another. +</blurb> </slide> http://cvs.php.net/diff.php/presentations/slides/intro/whyphp.xml?r1=1.1&r2=1.2&ty=u Index: presentations/slides/intro/whyphp.xml diff -u presentations/slides/intro/whyphp.xml:1.1 presentations/slides/intro/whyphp.xml:1.2 --- presentations/slides/intro/whyphp.xml:1.1 Thu Jun 24 09:07:07 2004 +++ presentations/slides/intro/whyphp.xml Wed Sep 22 15:15:35 2004 @@ -3,7 +3,7 @@ </blurb> <list fontsize="4em"> <bullet> Easy to learn and manage - well-documented</bullet> -<bullet> Worked well on existing FreeBSD/Apache platform</bullet> +<bullet> Works well on existing FreeBSD/Apache platform</bullet> <bullet> Easy to integrate existing C/C++ code</bullet> <bullet> Inherent HTML embedding</bullet> <bullet> Outperformed technologies it replaced</bullet> http://cvs.php.net/diff.php/presentations/slides/intro/xdebug.xml?r1=1.3&r2=1.4&ty=u Index: presentations/slides/intro/xdebug.xml diff -u presentations/slides/intro/xdebug.xml:1.3 presentations/slides/intro/xdebug.xml:1.4 --- presentations/slides/intro/xdebug.xml:1.3 Tue Jun 29 03:47:56 2004 +++ presentations/slides/intro/xdebug.xml Wed Sep 22 15:15:35 2004 @@ -22,16 +22,18 @@ successfully committed 16 file operations install ok: xdebug 1.3.0]]></example> - -<example title="Stack trace" result="1"><![CDATA[<?php +<example title="Stack trace" result="1" rfontsize="1.5em"><![CDATA[<?php $GLOBALS['trace'] = xdebug_start_trace('/tmp/xdebug.trace',true); function a() { b(); } function b() { + echo "<pre>"; readfile($GLOBALS['trace']); + echo "</pre>"; } a(); + xdebug_stop_trace(); ?>]]></example> <example title="Modified error handler" result="1"><![CDATA[<?php @@ -44,4 +46,8 @@ <image title="debugclient" filename="../xdebug/debugclient.png" align="center"/> +<example title="Enabling Profiling" fontsize="1.3em" type="shell">zend_extension=/usr/local/lib/php/xdebug.so +xdebug.profiler_enable=1 +xdebug.profile_output_dir=/tmp +xdebug.profile_output_name=crc32</example> </slide> http://cvs.php.net/co.php/presentations/tortech04.xml?r=1.1&p=1 Index: presentations/tortech04.xml +++ presentations/tortech04.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" > <!-- 90 Minutes You have used PHP for small projects for years, but how do you apply it to larger projects in a systematic way? In this talk, Rasmus will walk you through a set of steps that include the design, implementation, testing, benchmarking, profiling, optimization and deployment of large-scale PHP applications. --> <topic>PHP</topic> <title>Best Practices</title> <event>php|works</event> <location>Toronto</location> <date>September 22, 2004</date> <speaker>Rasmus Lerdorf</speaker> <email>rasmus@php.net</email> <url>http://talks.php.net/tortech04</url> <slide>slides/intro/titlepage.xml</slide> <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/image_cache.xml</slide> <slide>slides/intro/funky.xml</slide> <slide>slides/intro/file_layout.xml</slide> <slide>slides/intro/app_arch.xml</slide> </chapter> <chapter title="Implement"> <slide>slides/intro/layers_a.xml</slide> </chapter> <chapter title="Extending"> <slide>slides/intro/arch.xml</slide> <slide>slides/extending/ext4-bday.xml</slide> <slide>slides/extending/ext8.xml</slide> <slide>slides/extending/ext9.xml</slide> <slide>slides/extending/ext11.xml</slide> <slide>slides/extending/ext13.xml</slide> <slide>slides/intro/layers_b.xml</slide> <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/new_bench1.xml</slide> <slide>slides/intro/new_bench1a.xml</slide> <slide>slides/intro/new_bench2.xml</slide> <slide>slides/intro/new_bench3.xml</slide> <slide>slides/intro/new_bench4.xml</slide> <slide>slides/intro/php_profiling.xml</slide> <slide>slides/intro/xdebug.xml</slide> <slide>slides/intro/new_bench5.xml</slide> <slide>slides/intro/valgrind.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/file_layout.xml?r=1.1&p=1 Index: presentations/slides/intro/file_layout.xml +++ presentations/slides/intro/file_layout.xml <slide title="File Layout"> <blurb> </blurb> <blurb fontsize="5em">Keep it simple!</blurb> <list fontsize="4em"> <bullet>All files (.html/.php/.inc) with HTML under $DOC_ROOT</bullet> <bullet>All non-HTML files, somewhere else</bullet> </list> <blurb> </blurb> <blurb> </blurb> <blurb> </blurb> <blurb fontsize="5em">No direct access to .inc</blurb> <example><![CDATA[<Files ~ "\.inc$"> Order allow,deny Deny from all </Files>]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/layers_a.xml?r=1.1&p=1 Index: presentations/slides/intro/layers_a.xml +++ presentations/slides/intro/layers_a.xml <slide title="Simplistic Example"> <blurb> In terms of a real-world example of what goes in these 4 different layers, assume we are writing a database-backed application that needs to fetch a user record containing various fields. This is a very common thing to do in a web app. Our template layer might look something like this: </blurb> <example title="php.ini" type="shell"> auto_prepend_file = "./helpers.inc" include_path = "/usr/local/lib/php" </example> <example title="Template Layer"><![CDATA[<?title('Example Page')?> <?greeting()?> <h1>Heading 1</h1> <p> Page content </p> <h1>Heading 2</h1> <p> Yada Yada </p> <h1>Heading 3</h1> <p> Page content </p> <?footer()?> ]]></example> <example title="Template Helpers"><![CDATA[<?php include "logic.inc"; echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <?php $user = get_user_record($_COOKIE['user_id']); function greeting() { global $user; echo "Hi " .$user['first_name'] ."!<br />\n"; if($age=birthday($user)) { echo "Congratulations, today is your "; echo "$age birthday!<br />\n"; } } function title($title) { echo "<head><title>$title</title></head>\n"; echo "<body>\n"; } function footer() { echo "</body>\n</html>"; } ?>]]></example> <example title="Business Logic" fontsize="1.75em"><![CDATA[<?php function get_user_record($id) { mysql_connect('localhost'); mysql_select_db('users'); $res = mysql_query("select * from users where id='$id'"); if(!$res) echo mysql_error(); else $row = mysql_fetch_array($res); return $row; } function birthday($user) { if(strftime('%m %d')==strftime('%m %d',$user['bday'])) $age = strftime('%Y') - strftime('%Y',$user['bday']); if(($age%100)>10 && ($age%100)<20) $ap='th'; else switch($age%10) { case 1: $ap = 'st'; break; case 2: $ap = 'nd'; break; case 3: $ap = 'rd'; break; default: $ap = 'th'; break; } return $age.$ap; else return false; } ?>]]></example> <blurb> In this case the final layer written in C contains the ~mysql_*~ functions, and the ~date()~ function. These happen to be standard PHP functions. If ~birthday()~ is called many times on every single request and since how you figure out if it is someone's birthday is unlikely to change very often, this may be a good candidate to translate into C. Although, in this example, the birthday function is probably too simple to see much of a performance improvement. </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/intro/layers_b.xml?r=1.1&p=1 Index: presentations/slides/intro/layers_b.xml +++ presentations/slides/intro/layers_b.xml <slide title="Birthday Function"> <break lines="1" /> <example title="PHP Version" fontsize="1.5em"><![CDATA[<?php function birthday($user) { if(strftime('%m %d')==strftime('%m %d',$user['bday'])) $age = strftime('%Y') - strftime('%Y',$user['bday']); if(($age%100)>10 && ($age%100)<20) $ap='th'; else switch($age%10) { case 1: $ap = 'st'; break; case 2: $ap = 'nd'; break; case 3: $ap = 'rd'; break; default: $ap = 'th'; break; } return $age.$ap; else return false; } ?>]]></example> <blurb> Other than a little bit of added parameter parsing, if you compare the C version of ~birthday()~ to the PHP version, it isn't that much harder to write it in C. </blurb> <example title="C Version" fontsize="1.5em"><![CDATA[PHP_FUNCTION(birthday) { time_t timestamp, now; struct tm *ta1, tmbuf1, *ta2, tmbuf2; int age; char ret_age[8]; if (zend_parse_parameters(1 TSRMLS_CC, "l", &timestamp) == FAILURE) return; ta1 = php_localtime_r(&timestamp, &tmbuf1); time(&now); ta2 = php_localtime_r(&now, &tmbuf2); if(tmbuf1.tm_mday==tmbuf2.tm_mday && tmbuf1.tm_mon==tmbuf2.tm_mon) { age = tmbuf2.tm_year - tmbuf1.tm_year; if((age%100)>10 && (age%100)<19) sprintf(ret_age,"%dth",age); else switch(age % 10) { case 1: sprintf(ret_age,"%dst",age); break; case 2: sprintf(ret_age,"%dnd",age); break; case 3: sprintf(ret_age,"%drd",age); break; default:sprintf(ret_age,"%dth",age); break; } } else { RETURN_FALSE; } RETURN_STRING(ret_age,1); } ]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/new_apc.xml?r=1.1&p=1 Index: presentations/slides/intro/new_apc.xml +++ presentations/slides/intro/new_apc.xml <slide title="New APC Features"> <break lines="1" /> <list> <bullet>Better memory handling when getting near the shared memory limit.</bullet> <bullet>user-level access to store PHP variables in shared memory easily.</bullet> <bullet>Quick way to load constants from shared memory</bullet> </list> <example title="apc_store/fetch" result="1"><![CDATA[<?php $a = array(1,2,3,4,5); apc_store('my_array', $a, 5); $a = 0; print_r($a); $b = apc_fetch('my_array'); var_dump($b); ?>]]></example> <break lines="1" /> <example title="save/load constants" result="1"><![CDATA[<?php if(!apc_load_constants('my_constants')) { $constants = array('ABC'=>'testing', 'DEF'=>123, 'FOO'=>'Bar'); apc_define_constants('my_constants', $constants); } echo ABC,DEF,FOO; ?>]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/new_bench1.xml?r=1.1&p=1 Index: presentations/slides/intro/new_bench1.xml +++ presentations/slides/intro/new_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="Don't blow your io buffers!" type="shell"> # To change this on Linux, cat a larger number # into /proc/sys/net/core/wmem_max in your # httpd startup script SendBufferSize 65535 </example> <example title="This is our benchmark script" fontsize="1.5em" filename="newbench_main.php"/> <example title="bench_include1.inc" fontsize="1.5em" filename="bench_include1.inc"/> <example title="bench_include2.inc" fontsize="1.5em" filename="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/new_bench1a.xml?r=1.1&p=1 Index: presentations/slides/intro/new_bench1a.xml +++ presentations/slides/intro/new_bench1a.xml <slide title="Output"> <break lines="1" /> <example hide="1" result="1" rfontsize="1em" filename="newbench_main.php"/> </slide> http://cvs.php.net/co.php/presentations/slides/intro/new_bench2.xml?r=1.1&p=1 Index: presentations/slides/intro/new_bench2.xml +++ presentations/slides/intro/new_bench2.xml <slide title="Benchmarking Results"> <example type="shell" title="An http_load run" fontsize="1.5em"> 5000 fetches, 5 max parallel, 5.145e+07 bytes, in 15.4981 seconds 10290 mean bytes/connection 322.619 fetches/sec, 3.31975e+06 bytes/sec msecs/connect: 1.24853 mean, 13.075 max, 0.034 min msecs/first-response: 10.0517 mean, 2406.17 max, 2.888 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"> procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 3 0 0 695840 17452 150176 0 0 0 0 1005 2001 92 8 0 0 2 0 0 694936 17452 150212 0 0 0 0 1014 2013 94 6 0 0 3 0 0 693848 17452 150248 0 0 0 0 1004 1965 92 8 0 0 4 0 0 691840 17452 150284 0 0 0 0 1015 1963 92 8 0 0 5 0 0 691712 17452 150320 0 0 0 0 1008 1956 91 9 0 0 6 0 0 691648 17452 150356 0 0 0 0 1011 1971 92 8 0 0 1 0 0 691432 17452 150392 0 0 0 0 1003 1948 92 8 0 0 1 0 0 691368 17452 150424 0 0 0 0 1013 1956 90 10 0 0 1 0 0 691240 17452 150460 0 0 0 0 1003 1936 94 6 0 0 1 0 0 691176 17452 150496 0 0 0 0 1015 1953 92 8 0 0 2 0 0 691112 17452 150532 0 0 0 0 1007 1954 92 8 0 0 3 0 0 691048 17452 150568 0 0 0 0 1012 1961 92 8 0 0 1 0 0 690920 17452 150604 0 0 0 0 1007 1944 92 8 0 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"> [httpd.conf] LoadModule gzip_module lib/apache/mod_gzip.so </example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/new_bench3.xml?r=1.1&p=1 Index: presentations/slides/intro/new_bench3.xml +++ presentations/slides/intro/new_bench3.xml <slide title="Benchmarking Results"> <blurb> So, we have determined we are cpu-bound and we need to go faster. What can we do? Some low-hanging fruit: </blurb> <example title="include_path" type="shell"> include_path = "/usr/share/pear:." </example> <example><![CDATA[<?php include './template_helpers.inc'; include 'business_logic.inc'; ?>]]></example> <example title="open_basedir" type="shell" fontsize="1.75em"> open_basedir = "/usr/share/htdocs/:/usr/share/pear/" </example> <blurb>open_basedir checking adds some extra syscalls to every file operation. It can be useful, but it is rather expensive, so turn it off if you don't think you need it.</blurb> <example title="variables_order" type="shell"> variables_order = "GPC" </example> <example><![CDATA[<?php echo $_SERVER['DOCUMENT_ROOT']; echo getenv('DOCUMENT_ROOT'); ?>]]></example> <blurb>If you never use cookies, turn those off too</blurb> <example title="Output buffering?" type="shell" fontsize="1.75em"> output_buffering = On </example> <example title="Add an Opcode Cache" type="shell"> extension=apc.so apc.shm_segments=1 apc.shm_size=64 apc.num_files_hint=1000 apc.mmap_file_mask=/tmp/apc.XXXXXX </example> <example title="Switch to semaphore locking in APC" type="shell"> CPPFLAGS=-I/usr/include/apache-1.3 \../configure' --enable-apc --enable-mmap --enable-sem </example> <list title="Apply some of the hacks floating around"> <bullet>http://lerdorf.com/php/syscall.txt</bullet> <bullet>http://lerdorf.com/php/non-pic.txt</bullet> </list> </slide> http://cvs.php.net/co.php/presentations/slides/intro/new_bench4.xml?r=1.1&p=1 Index: presentations/slides/intro/new_bench4.xml +++ presentations/slides/intro/new_bench4.xml <slide title="Benchmarking Results"> <break lines="5" /> <example type="shell"> 322 requests/sec Standard PHP 4.3 325 requests/sec Turn on Output Buffering 325 requests/sec variables_order from EGPCS to GPC 345 requests/sec Compile PHP with non-pic patch 355 requests/sec Compile PHP with non-pic and syscall patch 385 requests/sec Standard PHP + APC 425 requests/sec syscall+nonpic+GPC+APC </example> <break lines="2" /> <blurb title="Perspective"> 322 requests/second is 1,159,200/hour or 27,820,800/day. </blurb> <blurb> 425 requests/second is 1,530,000/hour or 36,720,000/day. </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/intro/new_bench5.xml?r=1.1&p=1 Index: presentations/slides/intro/new_bench5.xml +++ presentations/slides/intro/new_bench5.xml <slide title="Profile"> <blurb> There is only so much you can do without changing your code. Your main speedups are usually going to come from rethinking your approach if it proves to be too slow. </blurb> <example title="Change the Rules!"><![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"> 322 requests/sec Standard PHP 4.3 325 requests/sec Turn on Output Buffering 325 requests/sec variables_order from EGPCS to GPC 345 requests/sec Compile PHP with non-pic patch 355 requests/sec Compile PHP with non-pic and syscall patch 385 requests/sec Standard PHP + APC 425 requests/sec syscall+nonpic+GPC+APC 570 requests/sec by cheating </example> <break lines="2" /> <blurb> 570 is 2,052,000 requests/hour or 49,248,000 request/day </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/intro/poll1.xml?r=1.1&p=1 Index: presentations/slides/intro/poll1.xml +++ presentations/slides/intro/poll1.xml <slide title="Template API"> <blurb> For larger projects you want to be very careful when designing how the layers talk to each other. I like to provide a very clean API to the template layer and start each project by thinking about what the ideal template should look like. </blurb> <blurb title="Poll Example"> Let's design a little application that allows people to answer a set of questions in various formats. We want to make it really easy for our content people to create new polls and we want to provide them with a flexible template API. </blurb> <example title="Poll Template"><![CDATA[<?php start_poll(1); $os = array("FreeBSD", "Linux","OSX", "Windows", "Other"); ?> <p class="purpose"> Please answer a couple of questions for us. </p> <p class="question"> 1. What is your name? </p> <?php text_answer('name',64)?> <p class="question"> 2. Which operating systems do you use on a daily basis? </p> <?php select_any_of($os)?> <p class="question"> 3. Which operating system do you prefer? </p> <?php select_one_of($os)?> <?php end_poll(); ?>]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/poll2.xml?r=1.1&p=1 Index: presentations/slides/intro/poll2.xml +++ presentations/slides/intro/poll2.xml <slide title="Template Helpers"> <blurb> In our template helper layer we implement our frontend API. </blurb> <example title="Helper Layer" fontsize="1.6em" marginright="0em" marginleft="1em"><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <base href="http://php.net" /> <title>Questionnaire</title> <style type="text/css" media="screen">@import "/poll/style.css";</style> </head> <body> <h3>Questionnaire</h3> <?php require 'logic.inc'; function start_poll($poll, $qn=1) { global $at_least_one_vote; init($poll, $qn); $at_least_one_vote = false; $self = getenv('REQUEST_URI'); // consider adding a crumb here to prevent poll spoofing echo <<<EOT <form action="$self" method="POST"> <div class="main_box"> EOT; } function end_poll() { global $at_least_one_vote; if(!$at_least_one_vote) { echo '<div align="center"><input type="submit" value=" Submit Answers " /></div></form>'; } else { echo '<div align="center"><input type="submit" value=" Change Answers "/></div></form>'; } echo "</div\n"; } function select_one_of($choices) { global $id, $qn, $at_least_one_vote; if(!is_array($choices)) trigger_error("You must pass an array to select_one_of()", E_USER_ERROR); // Grab the user's recorded answer to this question if any $answer = voted($id,$qn); $total_votes_on_this_question = total_votes($id,$qn); $i='a'; echo '<table class="results">'; foreach($choices as $c) { $checked = $answer?in_array($i,$answer):false; echo "<tr><td><input type=\"radio\" name=\"q[$qn][]\" value=\"$i\" ".($checked?'CHECKED':'')."/> $c</td>"; if($answer) { $at_least_one_vote = true; $percentage = 100*(($v=(int)results($id,$qn,$i))/ $total_votes_on_this_question); $img = ($percentage) ? ('<img src="/poll/bline.gif" height="12" width="'. (int)$percentage.'" />') : ''; echo "<td>&nbsp;$v of $total_votes_on_this_question (". sprintf("%.1f",$percentage)."%)</td><td> $img</td></tr>\n"; } else { echo '</tr>'; } $i++; } echo "</table>\n"; $qn++; } function select_any_of($choices) { global $id, $qn, $at_least_one_vote; if(!is_array($choices)) trigger_error("You must pass an array to select_any_of()", E_USER_ERROR); // Grab the user's recorded answer to this question if any $answer = voted($id,$qn); $total_votes_on_this_question = total_votes($id,$qn); $i='a'; echo '<table class="results">'; foreach($choices as $c) { $checked = $answer?in_array($i,$answer):false; echo "<tr><td><input type=\"checkbox\" name=\"q[$qn][]\" value=\"$i\" ".($checked?'CHECKED':'')."/> $c</td>"; if($answer) { $at_least_one_vote = true; $percentage = 100*(($v=(int)results($id,$qn,$i))/ $total_votes_on_this_question); $img = ($percentage>0.0) ? ('<img src="/poll/bline.gif" height="12" width="'. (int)$percentage.'" />') : ''; echo "<td>&nbsp;$v of $total_votes_on_this_question (". sprintf("%.1f",$percentage)."%)</td><td> $img</td></tr>\n"; } else { echo '</tr>'; } $i++; } echo "</table>\n"; $qn++; } function text_answer($field_name,$len) { global $id, $qn; $answer = get_text_answer($id,$qn); $size = (int)($len/2); echo <<<EOT <table class="results"> <tr><td> <input type="textfield" size="$size" maxlength="$len" name="t[$qn]" value="$answer" /> </td></tr> </table> EOT; $qn++; }?>]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/poll3.xml?r=1.1&p=1 Index: presentations/slides/intro/poll3.xml +++ presentations/slides/intro/poll3.xml <slide title="Application Logic"> <example title="SQL Schema" marginleft="1em" marginright="0em" fontsize="1.6em" type="php"><![CDATA[CREATE TABLE poll_votes ( user_name varchar(32) binary NOT NULL default '', poll_id smallint(6) NOT NULL default '0', question smallint(6) NOT NULL default '0', answer set("","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o", "p","q","r","s","t","u","v","w","x","y","z") NOT NULL default "", text_answer varchar(255) binary NOT NULL default '', PRIMARY KEY (user_name,poll_id,question) ) TYPE=MyISAM; CREATE TABLE poll_results ( poll_id smallint(6) NOT NULL default '0', question smallint(6) NOT NULL default '0', answer char(1) NOT NULL default '', text_answer varchar(255) binary NOT NULL default '', votes int(11) NOT NULL default '0', INDEX (poll_id) ) TYPE=MyISAM;]]></example> <example title="Logic Layer" marginleft="1em" marginright="0em" fontsize="1.6em"><![CDATA[<?php function db_connect() { mysql_pconnect("localhost","poll_user","password"); mysql_select_db("polls"); } function db_query($q) { $res = mysql_query($q); if(!$res) { trigger_error("db_query($q): ".mysql_error(), E_USER_ERROR); } return $res; } function voted($poll, $question) { global $user; $res = db_query("select answer from poll_votes where poll_id=$poll and user_name='$user' and question=$question"); return mysql_num_rows($res) ? mysql_result($res,0):false; } function total_votes($poll, $question) { $res = db_query("select sum(votes) as total from poll_results where poll_id=$poll and question=$question"); return mysql_num_rows($res) ? mysql_result($res,0):false; } function results($poll, $question, $answer) { $res = db_query("select votes from poll_results where poll_id=$poll and question=$question and answer=$answer"); return mysql_num_rows($res) ? mysql_result($res,0):false; } function init($poll, $start_qn = 1) { $GLOBALS['user'] = $user = $_SERVER['PHP_AUTH_USER']; $GLOBALS['qn'] = $start_qn; $GLOBALS['id'] = $poll; db_connect(); if(getenv('REQUEST_METHOD')=="POST") { // check bread crumb here foreach($_POST['q'] as $qn=>$answer) { if(($oanswer=voted($poll,$qn))!==false) { // if user already voted on this question, decrement old vote $where = "where poll_id=$poll and question=$qn and answer=$oanswer"; db_query("update poll_results set votes=votes-1 $where"); } // MySQL 4.1 specific query db_query("insert into poll_results values ($poll,$qn,$answer,1) on duplicate key update set votes=votes+1"); // record user's [new] answer in poll_votes db_query("replace into poll_votes values ('$user',$poll,$qn,$answer)"); } } } ?>]]></example> </slide> http://cvs.php.net/co.php/presentations/slides/intro/repl3.xml?r=1.1&p=1 Index: presentations/slides/intro/repl3.xml +++ presentations/slides/intro/repl3.xml <slide title="Bigger?"> <break lines="5" /> <image filename="repl3.png" align="center"/> </slide> http://cvs.php.net/co.php/presentations/slides/intro/tortech_goals.xml?r=1.1&p=1 Index: presentations/slides/intro/tortech_goals.xml +++ presentations/slides/intro/tortech_goals.xml <slide title="Goals"> <break lines="5" /> <list marginleft="5em" fontsize="6em"> <item>Design</item> <item>Implement</item> <item>Test and Benchmark</item> <item>Profile</item> <item>Optimize</item> <item>Deploy</item> <item>...</item> <item>Profit</item> </list> </slide>
« previous php.pres (#1063) next »