cvs: presentations / perf_tunning.xml sqlite_jan.xml /slides/perf_tunning apache.jpg bloat.jpg c_cflags.xml c_exten.xml c_static.xml c_strip.xml
cache.jpg casting.php casting.xml compiler.gif conf_apache.xml conf_apache2.xml conf_apache3.xml conf_php.xml conf_php2.xml content_caching.xml
content_caching_c.xml content_caching_mmcache.xml content_caching_php.php content_caching_php.xml content_caching_php2.xml content_compress.xml
content_compress_css.xml content_compress_tidy.xml content_compress_tidy2.xml content_compress_zlib.xml content_serve.xml content_serve2.xml
database.gif database_sm.gif ekg.jpg guestbook.php guestbook2.php includes.xml includes2.xml join.php keep_alive.xml lingerd.xml mysql.gif
opcode_bench.jpg opcode_bench2.jpg opcode_bench3.jpg opcode_benefits.xml opcode_cache.png opcode_comp.xml opcode_graph.xml opcode_imp.xml
opcode_intro.xml oracle.gif partial_caching.xml partial_caching_ex.php partial_caching_ex.xml postgresql.gif query_chain.php references.xml regex.jpg
regex.xml regex2.xml regex3.xml right_db.xml sessions.xml sessions2.xml sql_chain.xml sql_explain.xml sql_intro.xml sql_join.xml sql_locks.xml
sql_mysql4.xml sql_subquery.xml sql_tmp_tbl.xml strip.gif subquery.php thankyou.xml titlepage.xml tmp_table.php tmpfs.xml tmpfs2.xml vice.gif
/slides/sqlite_jan advantages.xml bsod.jpg chain.jpg close.xml db.sqlite db2.sqlite disadvantages.xml elephant.gif error.xml error_oo.xml escape.xml
fetch.php fetch.xml fetch2.php fetch2.xml fetch3.php fetch3.xml fetch4.php fetch4.xml fetch5.php fetch5.xml foreach.php foreach.xml future.gif
future.xml in-use.jpg iterators.xml itter.php libintro.xml library.jpg multi_query.xml oo.php oo.xml oo2.php oo2.xml open.xml open2.xml phpapi.xml
phpsql.php phpsql.xml phpsql2.php phpsql2.xml query.xml stats.jpg string.php string.xml string2.php string2.xml thankyou.xml titlepage.xml
unbuf_query.xml util2_oo.xml util3_oo.xml util_oo.xml utility2_oo.php utility3_oo.php utility_oo.php

From: Date: Fri, 16 Jan 2004 22:15:24 +0000
Subject: cvs: presentations / perf_tunning.xml sqlite_jan.xml /slides/perf_tunning apache.jpg bloat.jpg c_cflags.xml c_exten.xml c_static.xml c_strip.xml
cache.jpg casting.php casting.xml compiler.gif conf_apache.xml conf_apache2.xml conf_apache3.xml conf_php.xml conf_php2.xml content_caching.xml
content_caching_c.xml content_caching_mmcache.xml content_caching_php.php content_caching_php.xml content_caching_php2.xml content_compress.xml
content_compress_css.xml content_compress_tidy.xml content_compress_tidy2.xml content_compress_zlib.xml content_serve.xml content_serve2.xml
database.gif database_sm.gif ekg.jpg guestbook.php guestbook2.php includes.xml includes2.xml join.php keep_alive.xml lingerd.xml mysql.gif
opcode_bench.jpg opcode_bench2.jpg opcode_bench3.jpg opcode_benefits.xml opcode_cache.png opcode_comp.xml opcode_graph.xml opcode_imp.xml
opcode_intro.xml oracle.gif partial_caching.xml partial_caching_ex.php partial_caching_ex.xml postgresql.gif query_chain.php references.xml regex.jpg
regex.xml regex2.xml regex3.xml right_db.xml sessions.xml sessions2.xml sql_chain.xml sql_explain.xml sql_intro.xml sql_join.xml sql_locks.xml
sql_mysql4.xml sql_subquery.xml sql_tmp_tbl.xml strip.gif subquery.php thankyou.xml titlepage.xml tmp_table.php tmpfs.xml tmpfs2.xml vice.gif
/slides/sqlite_jan advantages.xml bsod.jpg chain.jpg close.xml db.sqlite db2.sqlite disadvantages.xml elephant.gif error.xml error_oo.xml escape.xml
fetch.php fetch.xml fetch2.php fetch2.xml fetch3.php fetch3.xml fetch4.php fetch4.xml fetch5.php fetch5.xml foreach.php foreach.xml future.gif
future.xml in-use.jpg iterators.xml itter.php libintro.xml library.jpg multi_query.xml oo.php oo.xml oo2.php oo2.xml open.xml open2.xml phpapi.xml
phpsql.php phpsql.xml phpsql2.php phpsql2.xml query.xml stats.jpg string.php string.xml string2.php string2.xml thankyou.xml titlepage.xml
unbuf_query.xml util2_oo.xml util3_oo.xml util_oo.xml utility2_oo.php utility3_oo.php utility_oo.php
Groups: php.pres 
Request: Send a blank email to pres+get-932@lists.php.net to get a copy of this message
iliaa Fri Jan 16 17:15:24 2004 EDT Added files: /presentations sqlite_jan.xml perf_tunning.xml /presentations/slides/sqlite_jan advantages.xml bsod.jpg chain.jpg close.xml db.sqlite db2.sqlite disadvantages.xml elephant.gif error.xml error_oo.xml escape.xml fetch.php fetch.xml fetch2.php fetch2.xml fetch3.php fetch3.xml fetch4.php fetch4.xml fetch5.php fetch5.xml foreach.php foreach.xml future.gif future.xml in-use.jpg iterators.xml itter.php libintro.xml library.jpg multi_query.xml oo.php oo.xml oo2.php oo2.xml open.xml open2.xml phpapi.xml phpsql.php phpsql.xml phpsql2.php phpsql2.xml query.xml stats.jpg string.php string.xml string2.php string2.xml thankyou.xml titlepage.xml unbuf_query.xml util2_oo.xml util3_oo.xml util_oo.xml utility2_oo.php utility3_oo.php utility_oo.php /presentations/slides/perf_tunning apache.jpg bloat.jpg c_cflags.xml c_exten.xml c_static.xml c_strip.xml cache.jpg casting.php casting.xml compiler.gif conf_apache.xml conf_apache2.xml conf_apache3.xml conf_php.xml conf_php2.xml content_caching.xml content_caching_c.xml content_caching_mmcache.xml content_caching_php.php content_caching_php.xml content_caching_php2.xml content_compress.xml content_compress_css.xml content_compress_tidy.xml content_compress_tidy2.xml content_compress_zlib.xml content_serve.xml content_serve2.xml database.gif database_sm.gif ekg.jpg guestbook.php guestbook2.php includes.xml includes2.xml join.php keep_alive.xml lingerd.xml mysql.gif opcode_bench.jpg opcode_bench2.jpg opcode_bench3.jpg opcode_benefits.xml opcode_cache.png opcode_comp.xml opcode_graph.xml opcode_imp.xml opcode_intro.xml oracle.gif partial_caching.xml partial_caching_ex.php partial_caching_ex.xml postgresql.gif query_chain.php references.xml regex.jpg regex.xml regex2.xml regex3.xml right_db.xml sessions.xml sessions2.xml sql_chain.xml sql_explain.xml sql_intro.xml sql_join.xml sql_locks.xml sql_mysql4.xml sql_subquery.xml sql_tmp_tbl.xml strip.gif subquery.php thankyou.xml titlepage.xml tmp_table.php tmpfs.xml tmpfs2.xml vice.gif Log: Added SQlite & Performance Tuning presentations for Vancouver conference.

Index: presentations/sqlite_jan.xml +++ presentations/sqlite_jan.xml <presentation template="php2" titlecolor="#1111aa" navbarbackground="url(images/trans-ffffff.png)" logo1="images/php-med-trans-light.gif" titlesize="2em" navbarheight="4.1em"> <topic>SQLite</topic> <title>Introduction to SQLite</title> <copyright>(c) Copyright 2004 Ilia Alshanetsky</copyright> <event></event> <location>Vancouver, Canada</location> <date>January 22th 2004</date> <speaker>Ilia Alshanetsky</speaker> <navmode>html</navmode> <url>http://talks.php.net/</url> <slide>slides/sqlite_jan/titlepage.xml</slide> <slide>slides/sqlite_jan/libintro.xml</slide> <slide>slides/sqlite_jan/phpapi.xml</slide> <slide>slides/sqlite_jan/advantages.xml</slide> <slide>slides/sqlite_jan/disadvantages.xml</slide> <slide>slides/sqlite_jan/open.xml</slide> <slide>slides/sqlite_jan/open2.xml</slide> <slide>slides/sqlite_jan/close.xml</slide> <slide>slides/sqlite_jan/query.xml</slide> <slide>slides/sqlite_jan/unbuf_query.xml</slide> <slide>slides/sqlite_jan/multi_query.xml</slide> <slide>slides/sqlite_jan/escape.xml</slide> <slide>slides/sqlite_jan/error.xml</slide> <slide>slides/sqlite_jan/error_oo.xml</slide> <slide>slides/sqlite_jan/fetch.xml</slide> <slide>slides/sqlite_jan/fetch2.xml</slide> <slide>slides/sqlite_jan/fetch3.xml</slide> <slide>slides/sqlite_jan/fetch4.xml</slide> <slide>slides/sqlite_jan/oo.xml</slide> <slide>slides/sqlite_jan/oo2.xml</slide> <slide>slides/sqlite_jan/string.xml</slide> <slide>slides/sqlite_jan/string2.xml</slide> <slide>slides/sqlite_jan/iterators.xml</slide> <slide>slides/sqlite_jan/foreach.xml</slide> <slide>slides/sqlite_jan/util_oo.xml</slide> <slide>slides/sqlite_jan/util2_oo.xml</slide> <slide>slides/sqlite_jan/util3_oo.xml</slide> <slide>slides/sqlite_jan/phpsql.xml</slide> <slide>slides/sqlite_jan/phpsql2.xml</slide> <slide>slides/sqlite_jan/future.xml</slide> <slide>slides/sqlite_jan/thankyou.xml</slide> </presentation> Index: presentations/perf_tunning.xml +++ presentations/perf_tunning.xml <presentation template="php2" titlecolor="#1111aa" navbarbackground="url(images/trans-ffffff.png)" logo1="images/php-med-trans-light.gif" titlesize="2em" navbarheight="4.1em"> <topic>PHP</topic> <title>Performance Tuning PHP</title> <copyright>(c) Copyright 2004 Ilia Alshanetsky</copyright> <event></event> <location>Vancouver, Canada</location> <date>January 23th 2004</date> <speaker>Ilia Alshanetsky</speaker> <navmode>html</navmode> <url>http://talks.php.net/</url> <slide>slides/perf_tunning/titlepage.xml</slide> <slide>slides/perf_tunning/c_cflags.xml</slide> <slide>slides/perf_tunning/c_exten.xml</slide> <slide>slides/perf_tunning/c_static.xml</slide> <slide>slides/perf_tunning/c_strip.xml</slide> <slide>slides/perf_tunning/conf_php.xml</slide> <slide>slides/perf_tunning/conf_php2.xml</slide> <slide>slides/perf_tunning/conf_apache.xml</slide> <slide>slides/perf_tunning/conf_apache2.xml</slide> <slide>slides/perf_tunning/conf_apache3.xml</slide> <slide>slides/perf_tunning/keep_alive.xml</slide> <slide>slides/perf_tunning/lingerd.xml</slide> <slide>slides/perf_tunning/content_serve.xml</slide> <slide>slides/perf_tunning/content_serve2.xml</slide> <slide>slides/perf_tunning/opcode_intro.xml</slide> <slide>slides/perf_tunning/opcode_graph.xml</slide> <slide>slides/perf_tunning/opcode_benefits.xml</slide> <slide>slides/perf_tunning/opcode_imp.xml</slide> <slide>slides/perf_tunning/opcode_comp.xml</slide> <slide>slides/perf_tunning/content_caching.xml</slide> <slide>slides/perf_tunning/content_caching_php.xml</slide> <slide>slides/perf_tunning/content_caching_php2.xml</slide> <slide>slides/perf_tunning/content_caching_mmcache.xml</slide> <slide>slides/perf_tunning/content_caching_c.xml</slide> <slide>slides/perf_tunning/partial_caching.xml</slide> <slide>slides/perf_tunning/partial_caching_ex.xml</slide> <slide>slides/perf_tunning/content_compress.xml</slide> <slide>slides/perf_tunning/content_compress_zlib.xml</slide> <slide>slides/perf_tunning/content_compress_css.xml</slide> <slide>slides/perf_tunning/content_compress_tidy.xml</slide> <slide>slides/perf_tunning/content_compress_tidy2.xml</slide> <slide>slides/perf_tunning/includes.xml</slide> <slide>slides/perf_tunning/includes2.xml</slide> <slide>slides/perf_tunning/tmpfs.xml</slide> <slide>slides/perf_tunning/tmpfs2.xml</slide> <slide>slides/perf_tunning/sessions.xml</slide> <slide>slides/perf_tunning/sessions2.xml</slide> <slide>slides/perf_tunning/sql_intro.xml</slide> <slide>slides/perf_tunning/sql_explain.xml</slide> <slide>slides/perf_tunning/sql_chain.xml</slide> <slide>slides/perf_tunning/sql_locks.xml</slide> <slide>slides/perf_tunning/sql_mysql4.xml</slide> <slide>slides/perf_tunning/sql_join.xml</slide> <slide>slides/perf_tunning/sql_subquery.xml</slide> <slide>slides/perf_tunning/sql_tmp_tbl.xml</slide> <slide>slides/perf_tunning/right_db.xml</slide> <slide>slides/perf_tunning/regex.xml</slide> <slide>slides/perf_tunning/regex2.xml</slide> <slide>slides/perf_tunning/regex3.xml</slide> <slide>slides/perf_tunning/casting.xml</slide> <slide>slides/perf_tunning/references.xml</slide> <slide>slides/perf_tunning/thankyou.xml</slide> </presentation> Index: presentations/slides/sqlite_jan/advantages.xml +++ presentations/slides/sqlite_jan/advantages.xml <slide title="SQLite Advantages"> <image filename="in-use.jpg" align="right" /> <blurb title="Why use SQLite?"/> <list> <bullet fontsize="2.5em">Speed</bullet> <bullet marginleft="1.5em">In many cases at least 2-3 times faster then MySQL/PostgreSQL.</bullet> <bullet marginleft="1.5em">Fast PHP interface.</bullet> <bullet marginleft="1.5em">No socket and/or TCP/IP overhead.</bullet> <bullet fontsize="2.5em">Functionality</bullet> <bullet marginleft="1.5em">Sub-selects, Triggers, Transactions, Views.</bullet> <bullet marginleft="1.5em">Up to 2TB of data storage.</bullet> <bullet marginleft="1.5em">Small memory footprint.</bullet> <bullet marginleft="1.5em">Self-contained: no external dependencies.</bullet> <bullet marginleft="1.5em">Atomic commit and rollback protect data integrity.</bullet> <bullet marginleft="1.5em">Easily movable database.</bullet> <bullet fontsize="2.5em">Security</bullet> <bullet marginleft="1.5em">Each user has their own completely independent database(s).</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/close.xml +++ presentations/slides/sqlite_jan/close.xml <slide title="Closing a Database"> <break /> <example fontsize="1.6em" title=""><![CDATA[<?php /* Procedural Approach */ $db = sqlite_open("/path/to/database"); /* void sqlite_close(resource database_handle) */ sqlite_close($db); ?>]]> </example> <example fontsize="1.6em" title=""><![CDATA[<?php /* Object Oriented Approach */ $db = new sqlite_db("/path/to/database"); unset($db); ?>]]> </example> <list> <bullet>In most cases optional as PHP will automatically close non-persistent connections.</bullet> <bullet>Unlike in other database extensions sqlite_close() can &amp; will close persistent connections.</bullet> <bullet>For OO there is no dedicated 'close' method, so to close the connection you simply destroy the database object.</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/db.sqlite +++ presentations/slides/sqlite_jan/db.sqlite ** This file contains an SQLite 2.1 database **(uãښät[€  [tableauth_tblauth_tbl3CREATE TABLE auth_tbl (login VARCHAR(32), passwd CHAR(32))_€ _tablefoobarfoobar4CREATE TABLE foobar ( id INTEGER PRIMARY KEY, misc CHAR(10) )@€D)€)root0b2c539c3e7f85d808df3f2dfe8906b9Äÿ¿)€)ilia63a9f0ea7bb98050796b649e85481845Äÿ¿€T €Wez3< € Marcus€Ilia¬ Index: presentations/slides/sqlite_jan/db2.sqlite +++ presentations/slides/sqlite_jan/db2.sqlite ** This file contains an SQLite 2.1 database **(uãڋ„x`€  `tablemessagesmessages3CREATE TABLE messages ( timestamp INTEGER, title VARCHAR(255) )ìd€ dtableprofileprofile4CREATE TABLE profile ( time_format VARCHAR(255), login VARCHAR(255) )46€ 6tablefoofoo5CREATE TABLE foo (blah INTEGER)>€ >indexblah_idxfoo6CREATE INDEX blah_idx ON foo(blah)@|ä4€1072917852message #0Äÿ¿`€1075805801message #1Äÿ¿Œ€1072569394message #2Äÿ¿¸€1093372191message #3Äÿ¿€1086762828message #4Äÿ¿4€l dS of F Y h:i:s AiliaÌøø Index: presentations/slides/sqlite_jan/disadvantages.xml +++ presentations/slides/sqlite_jan/disadvantages.xml <slide title="SQLite Disadvantages"> <image filename="stats.jpg" align="center" /> <list> <bullet fontsize="4em">It's Slow</bullet> <bullet fontsize="3.2em" marginleft="1.5em">Locks whole file for writing.</bullet> <bullet fontsize="3.2em" marginleft="1.5em">No caching mechanism of it's own.</bullet> <bullet fontsize="4em">Limited</bullet> <bullet marginleft="1.5em" fontsize="3.2em">Database size restricted to 2GB in most cases.</bullet> <bullet marginleft="1.5em" fontsize="3.2em">Not fully SQL92 compliant.</bullet> <bullet marginleft="1.5em" fontsize="3.2em">Not very scalable.</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/error.xml +++ presentations/slides/sqlite_jan/error.xml <slide title="Error Handling"> <image filename="bsod.jpg" align="right" /> <blurb>SQLite allows retrieval of a numeric error codes allowing for custom handling of different errors. It also provides a mechanism for converting an error code into a human readable error string.</blurb> <break lines="3" /> <example fontsize="1.6em" title=""><![CDATA[<?php /* Procedural Approach */ $db = sqlite_open("/path/to/database"); $result = sqlite_query("INSERT INTO tbl VALUES(1,2,3)", $db); if (!$result) { /* get a numeric code for the error */ $error_code = sqlite_last_error($db); /* use the error code to get a readable error */ $error_str = sqlite_error_string($error_code); } ?>]]> </example> </slide> Index: presentations/slides/sqlite_jan/error_oo.xml +++ presentations/slides/sqlite_jan/error_oo.xml <slide title="Error Handling OO"> <image filename="bsod.jpg" align="right" /> <blurb>While fetching of the error code is possible via OO, the retrieval of a text error is done via sqlite_escape_string().</blurb> <break lines="4" /> <example fontsize="1.6em" title=""><![CDATA[<?php /* Object Oriented Approach */ $db = new sqlite_db("/path/to/database"); $r = $db->query("INSERT INTO tbl VALUES(1,2,3)"); if (!$r) { $error_code = $db->last_error(); $error_str = sqlite_error_string($error_code); } ?>]]> </example> </slide> Index: presentations/slides/sqlite_jan/escape.xml +++ presentations/slides/sqlite_jan/escape.xml <slide title="Securing SQLite Queries"> <blurb>SQLite has it's own query escaping function, sqlite_escape_string() which in addition to preventing SQL injection, which is particularly dangerous due to query chaining capability will safely handle binary data.</blurb> <example fontsize="1.6em" title=""><![CDATA[<?php $db = sqlite_open("/path/to/database") or die($error); $query = 'BEGIN;'; for ($i = 0; $i < 10; $i++) { $query .= "INSERT INTO tbl VALUES(".sqlite_escape_string($_POST['field_'.$i]).");"; } $query .= "COMMIT;" sqlite_query($query, $db); ?>]]> </example> <list> <bullet>|FF0000|Binary encoding performed by sqlite_escape_string() will make LIKE comparisons unusable.|</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/fetch.php +++ presentations/slides/sqlite_jan/fetch.php <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); /* CREATE TABLE auth_tbl (login VARCHAR(32), passwd CHAR(32)); */ $result = sqlite_query("SELECT * FROM auth_tbl", $db); echo '<pre>'; /* array sqlite_fetch_array(resource result [, int result_type [, bool decode_binary]] ) */ while (($row = sqlite_fetch_array($result))) { print_r($row); } echo '</pre>'; sqlite_close($db); ?> Index: presentations/slides/sqlite_jan/fetch.xml +++ presentations/slides/sqlite_jan/fetch.xml <slide title="Array Data Retrieval"> <blurb>Data retrieval is almost always done in a form of an array.</blurb> <example fontsize="1.6em" result="1" type="php" filename="fetch.php" /> <blurb>By default, result_type is set to SQLITE_BOTH and decode_binary is enabled.</blurb> </slide> Index: presentations/slides/sqlite_jan/fetch2.php +++ presentations/slides/sqlite_jan/fetch2.php <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); $result = sqlite_query("SELECT * FROM auth_tbl LIMIT 1", $db); echo '<pre>'; while (($row = sqlite_fetch_array($result, SQLITE_ASSOC))) print_r($row); echo '</pre>'; ?> Index: presentations/slides/sqlite_jan/fetch2.xml +++ presentations/slides/sqlite_jan/fetch2.xml <slide title="Array Data Retrieval II"> <blurb>In most cases you will not need both the numeric and string keys, so you can benefit from the increased performance of just using SQLITE_ASSOC (string keys) or SQLITE_NUM (numeric keys).</blurb> <example fontsize="1.6em" result="1" type="php" filename="fetch2.php" /> <example fontsize="1.6em" result="1" type="php" filename="fetch3.php" /> <blurb>If performance is a main concern, use the SQLITE_NUM mode of retrieval, it is 5-10% faster depending on the number of columns.</blurb> </slide> Index: presentations/slides/sqlite_jan/fetch3.php +++ presentations/slides/sqlite_jan/fetch3.php <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); $result = sqlite_query("SELECT * FROM auth_tbl LIMIT 1", $db); echo '<pre>'; while (($row = sqlite_fetch_array($result, SQLITE_NUM))) print_r($row); echo '</pre>'; ?> Index: presentations/slides/sqlite_jan/fetch3.xml +++ presentations/slides/sqlite_jan/fetch3.xml <slide title="Array Data Retrieval III"> <blurb>When dealing with small result sets you can improve the data retrieval performance by using sqlite_fetch_all(), which will retrieve all rows at once.</blurb> <example fontsize="1.6em" result="1" type="php" filename="fetch4.php" /> </slide> Index: presentations/slides/sqlite_jan/fetch4.php +++ presentations/slides/sqlite_jan/fetch4.php <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); $result = sqlite_query("SELECT * FROM auth_tbl", $db); echo '<pre>'; /* array sqlite_fetch_all(resource result [, int result_type [, bool decode_binary]]) */ var_dump(sqlite_fetch_all($result, SQLITE_ASSOC)); echo '</pre>'; sqlite_close($db); ?> Index: presentations/slides/sqlite_jan/fetch4.xml +++ presentations/slides/sqlite_jan/fetch4.xml <slide title="Array Data Retrieval IV"> <blurb>For even faster data retrieval and shorter code you can combine query execution with data retrieval via sqlite_array_query().</blurb> <example fontsize="1.6em" result="1" type="php" filename="fetch5.php" /> <blurb>Internally sqlite_array_query() will execute an unbuffered query to minimize memory usage.</blurb> </slide> Index: presentations/slides/sqlite_jan/fetch5.php +++ presentations/slides/sqlite_jan/fetch5.php <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); echo '<pre>'; /* array sqlite_array_query(string query, resource db [ , int result_type [, bool decode_binary]]) */ var_dump(sqlite_array_query("SELECT * FROM auth_tbl", $db, SQLITE_ASSOC)); echo '</pre>'; sqlite_close($db); ?> Index: presentations/slides/sqlite_jan/fetch5.xml +++ presentations/slides/sqlite_jan/fetch5.xml <slide title="Arrays via OO Model"> <blurb>All of the array functions are avaliable via the OO interface as well.</blurb> <example fontsize="1.6em" title=""><![CDATA[<?php $db = new sqlite_db(dirname(__FILE__)."/db.sqlite"); $result = $db->query("SELECT * FROM auth_tbl"); /* sqlite_result->fetch_array([, int result_type [, bool decode_binary]]) */ while ($row = $result->fetch_array(SQLITE_ASSOC)) { print_r($row); } $result = $db->query("SELECT * FROM auth_tbl"); /* sqlite_result->fetch_all([, int result_type [, bool decode_binary]]) */ print_r($result->fetch_all(SQLITE_NUM)); /* array sqlite_object->array_query(string query [ , int result_type [, bool decode_binary]]) */ print_r($db->array_query("SELECT * FROM auth_tbl", SQLITE_BOTH)); ?>]]> </example> </slide> Index: presentations/slides/sqlite_jan/foreach.php +++ presentations/slides/sqlite_jan/foreach.php <pre> <?php $db = new sqlite_db(dirname(__FILE__)."/db.sqlite"); foreach($db->query("SELECT * FROM auth_tbl", SQLITE_NUM) as $row) { print_r($row); } ?> </pre> Index: presentations/slides/sqlite_jan/foreach.xml +++ presentations/slides/sqlite_jan/foreach.xml <slide title="SQLite Iterators/Foreach"> <blurb>The real power of iterators comes through the ability to overload foreach allowing an extremely fast way for iterating through object properties. <![CDATA[<font color="red">(PHP5 only)</font>]]></blurb> <example fontsize="1.6em" result="1" type="php" filename="foreach.php" /> </slide> Index: presentations/slides/sqlite_jan/future.xml +++ presentations/slides/sqlite_jan/future.xml <slide title="Future of the SQLite Extension" fontsize="6em"> <image filename="future.gif" align="center" /> <blurb title="Pre-compiled SQL"> Ability to pre-compile SQL statements so that they need not be parsed every time they are executed. </blurb> <blurb title="PEAR Library"> A set of functions &amp; classes for PEAR that can be used to implement various useful functions to be used from within SQL. </blurb> </slide> Index: presentations/slides/sqlite_jan/iterators.xml +++ presentations/slides/sqlite_jan/iterators.xml <slide title="SQLite Iterators"> <blurb>Yet another method of retrieving information from a query, using iterators.</blurb> <example fontsize="1.6em" result="1" type="php" filename="itter.php" /> </slide> Index: presentations/slides/sqlite_jan/itter.php +++ presentations/slides/sqlite_jan/itter.php <pre> <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); $res = sqlite_query("SELECT login FROM auth_tbl", $db); /* got rows? */ while (sqlite_has_more($res)) { /* fetch one row */ print_r(sqlite_current($res, SQLITE_NUM)); /* move along */ sqlite_next($res); } sqlite_close($db); ?> </pre> Index: presentations/slides/sqlite_jan/libintro.xml +++ presentations/slides/sqlite_jan/libintro.xml <slide title="SQLite Library" fontsize="6em"> <image filename="library.jpg" align="center" /> <list fontsize="4em"> <bullet padding="0.5em">SQLite is a C library that implements an embeddable SQL database engine.</bullet> <bullet padding="0.5em">Started in 2000 by D. Richard Hipp.</bullet> <bullet padding="0.5em">Implements majority of SQL92 standard.</bullet> <bullet padding="0.5em">Combines the database and the interface inside a single library.</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/multi_query.xml +++ presentations/slides/sqlite_jan/multi_query.xml <slide title="Chaining Queries"> <image filename="chain.jpg" align="right" /> <blurb>Query chaining allows for execution of any number of queries via a single PHP function.</blurb> <example fontsize="1.6em" title=""><![CDATA[<?php $db = sqlite_open("/path/to/database"); /* Execute 10 inserts via a single query */ $query = 'BEGIN;'; for ($i = 0; $i < 10; $i++) { $query .= "INSERT INTO tbl VALUES(".$i.");"; } $query .= "COMMIT;" sqlite_query($query, $db); ?>]]> </example> <list> <bullet>|00AA00|Faster, thanks to reduced PHP overhead.|</bullet> <bullet>|FF0000|Information available only about the effect of the last query.|</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/oo.php +++ presentations/slides/sqlite_jan/oo.php <pre> <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); $res = sqlite_query("SELECT * FROM auth_tbl", $db); /* fetch each row as an object */ while (($obj = sqlite_fetch_object($res))) { var_dump($obj); } sqlite_close($db); ?> </pre> Index: presentations/slides/sqlite_jan/oo.xml +++ presentations/slides/sqlite_jan/oo.xml <slide title="Results as Objects"> <blurb>So far we've seen SQLite retrieve data in the form of array, but it can just as easily return them as objects.</blurb> <example fontsize="1.6em" result="1" type="php" filename="oo.php" /> </slide> Index: presentations/slides/sqlite_jan/oo2.php +++ presentations/slides/sqlite_jan/oo2.php <pre> <?php class my_class { public $from_db, $row_num=0; public $passwd; /* constructor sets the row number * and sets a flag indicating * that the data originated from the database */ function __construct($row=0, $fdb=FALSE) { $this->row_num = $row; $this->from_db = $fdb; } } $db = new sqlite_db(dirname(__FILE__)."/db.sqlite"); $res = $db->query("SELECT * FROM auth_tbl"); $i = 0; /* import result into my_class setting the row number * and indicating that the data is from a database */ while (($obj = $res->fetch_object("my_class", array(++$i, TRUE)))) { var_dump($obj); } ?> </pre> Index: presentations/slides/sqlite_jan/oo2.xml +++ presentations/slides/sqlite_jan/oo2.xml <slide title="Results as Objects"> <blurb>Unlike other database extensions SQLite also has the ability to import data into existing class definitions.</blurb> <example fontsize="1.6em" result="1" type="php" filename="oo2.php" /> </slide> Index: presentations/slides/sqlite_jan/open.xml +++ presentations/slides/sqlite_jan/open.xml <slide title="Opening a Database"> <blurb>As with any database system the first thing you must do is open a database. Since SQLite is based on files opening a database differs very little from opening a regular file.</blurb> <example fontsize="1.6em" title=""><![CDATA[<?php /* resource sqlite_open(string filename [, int mode [, string &error_message]]) */ $db = sqlite_open("db.sqlite", 0666, $error) or die("Failed to connect because: ".$error); /* opened a connection to memory only database */ ?>]]> </example> <list> <bullet>PHP file system checks (safe_mode, open_basedir) are performed on the database path.</bullet> <bullet>If the database does not exist it will be created.</bullet> <bullet>The optional mode parameter can be used to open the database in read-only mode.</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/open2.xml +++ presentations/slides/sqlite_jan/open2.xml <slide title="Opening a Database via OO"> <blurb>SQLite offers a built-in OO interface to the database without the need for PHP wrappers.</blurb> <example fontsize="1.6em" title=""><![CDATA[<?php try { /* object sqlite_db(string filename [, int mode [, string &error_message]]) */ $db = new sqlite_db(":memory:"); } /* Error occur let's handle it * In php5 unhandled exceptions result in fatal errors */ catch (Exception $exception) { echo $exception; } ?>]]> </example> <list> <bullet>No support for persistent connections (yet).</bullet> <bullet>OO interface is simpler and faster then the procedural one.</bullet> <bullet>Instead of regular errors, OO code throws exceptions when fatal errors occur.</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/phpapi.xml +++ presentations/slides/sqlite_jan/phpapi.xml <slide title="PHP Interface to SQLite"> <image filename="elephant.gif" align="right" /> <list fontsize="4em"> <bullet padding="0.5em">Brand new, legacy free code.</bullet> <bullet padding="0.5em">Developed by Wez Furlong &amp; Marcus Boerger in April 2003.</bullet> <bullet marginleft="3em">PECL for PHP 4.3.X</bullet> <bullet marginleft="3em">Bundled with PHP 5</bullet> <bullet padding="0.5em">Fastest database library interface.</bullet> <bullet padding="0.5em">Library &amp; Database part of the extension</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/phpsql.php +++ presentations/slides/sqlite_jan/phpsql.php <?php $db = sqlite_open(dirname(__FILE__)."/db2.sqlite"); /* bool sqlite_create_function ( resource dbhandle, string function_name, mixed callback [, int num_args]) */ sqlite_create_function($db, "my_date", "date", 2); /* the above function makes PHP date() avaliable from SQLite as my_date() * and for highest performance indicates that it requires exactly 2 arguments */ $res = sqlite_array_query("SELECT title, my_date((SELECT time_format FROM profile WHERE login='ilia'), timestamp) AS date FROM messages", $db, SQLITE_ASSOC); foreach ($res as $v) { echo $v['title'] . " was posted on " . $v['date'] . "<br />\n"; } sqlite_close($db); ?> Index: presentations/slides/sqlite_jan/phpsql.xml +++ presentations/slides/sqlite_jan/phpsql.xml <slide title="PHP in SQL"> <blurb>Because the SQLite library is both a client and a database you have the ability to call PHP function(s) from within SQL queries.</blurb> <example fontsize="1.6em" result="1" type="php" filename="phpsql.php" /> </slide> Index: presentations/slides/sqlite_jan/phpsql2.php +++ presentations/slides/sqlite_jan/phpsql2.php <?php function most_similar(&$context, $string, $source_str) { /* Calculate the similarity between two strings */ $sim = similar_text($string, $source_str); if (empty($context) || $sim > $context['sim']) { $context = array('sim'=>$sim, 'title'=>$string); } } function most_similar_finalize(&$context) { return $context['title']; } $db = sqlite_open(dirname(__FILE__)."/db2.sqlite"); /* bool sqlite_create_aggregate (resource dbhandle, string function_name, mixed step_func, mixed finalize_func [, int num_args]) */ sqlite_create_aggregate($db, 'similar_text', 'most_similar', 'most_similar_finalize', 2); $title = 'mesg #2'; echo "Most Similar title to '{$title}' according to similar_text() is: "; echo sqlite_single_query("SELECT similar_text(title, '{$title}') FROM messages", $db); echo "<br />\n"; ?> Index: presentations/slides/sqlite_jan/phpsql2.xml +++ presentations/slides/sqlite_jan/phpsql2.xml <slide title="PHP in SQL Aggregation"> <blurb>You can also create PHP functions that can be used to aggregate data.</blurb> <example fontsize="1.6em" result="1" type="php" filename="phpsql2.php" /> </slide> Index: presentations/slides/sqlite_jan/query.xml +++ presentations/slides/sqlite_jan/query.xml <slide title="Running Queries"> <break /> <example fontsize="1.6em" title=""><![CDATA[<?php /* Procedural Approach */ $db = sqlite_open("/path/to/database"); $result = sqlite_query("INSERT INTO tbl VALUES(1,2,3)", $db); /* OR */ $result = sqlite_query($db, "INSERT INTO tbl VALUES(1,2,3)"); ?>]]> </example> <blurb>For compatibility, procedural approach supports both MySQL &amp; PostgreSQL/MSSQL/Etc... syntaxes.</blurb> <example fontsize="1.6em" title=""><![CDATA[<?php /* Object Oriented Approach */ $db = new sqlite_db("/path/to/database"); $db->query("INSERT INTO tbl VALUES(1,2,3)"); ?>]]> </example> </slide> Index: presentations/slides/sqlite_jan/string.php +++ presentations/slides/sqlite_jan/string.php <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); $res = sqlite_query("SELECT login FROM auth_tbl", $db); /* fetch the column as a string */ while (($login = sqlite_fetch_single($res))) { echo $login . "<br />\n"; } sqlite_close($db); ?> Index: presentations/slides/sqlite_jan/string.xml +++ presentations/slides/sqlite_jan/string.xml <slide title="Results as Strings"> <blurb>SQLite also offers a highly optimized method of retrieving single column data.</blurb> <example fontsize="1.6em" result="1" type="php" filename="string.php" /> </slide> Index: presentations/slides/sqlite_jan/string2.php +++ presentations/slides/sqlite_jan/string2.php <pre> <?php $db = sqlite_open(dirname(__FILE__)."/db.sqlite"); print_r(sqlite_single_query("SELECT login FROM auth_tbl", $db)); sqlite_close($db); ?> </pre> Index: presentations/slides/sqlite_jan/string2.xml +++ presentations/slides/sqlite_jan/string2.xml <slide title="Results as Strings II"> <blurb>As with arrays, for increased performance you can combine data retrieval with query execution.</blurb> <example fontsize="1.6em" result="1" type="php" filename="string2.php" /> <blurb>Since there is more then 1 row being returned the result in actually an array with numeric indexes rather then a plain string.</blurb> </slide> Index: presentations/slides/sqlite_jan/thankyou.xml +++ presentations/slides/sqlite_jan/thankyou.xml <slide title="Thank You!" fontsize="6em"> <blurb title="Find more information online..." /> <break /> <link fontsize="2.5em" marginleft="2em" leader="SQLite Homepage: ">http://www.sqlite.org/</link> <link fontsize="2.5em" marginleft="2em" leader="PHP SQLite Homepage: ">http://pecl.php.net/sqlite</link> <link fontsize="2.5em" marginleft="2em" leader="PHP SQLite Documentation: ">http://www.php.net/sqlite</link> <break lines="2" /> <blurb title="Contact Me" /> <link fontsize="2.5em" marginleft="2em" leader="Ilia Alshanetsky ">ilia@php.net</link> </slide> Index: presentations/slides/sqlite_jan/titlepage.xml +++ presentations/slides/sqlite_jan/titlepage.xml <slide template="titlepage" fontsize="6em"> <title>Welcome!</title> </slide> Index: presentations/slides/sqlite_jan/unbuf_query.xml +++ presentations/slides/sqlite_jan/unbuf_query.xml <slide title="Running Unbuffered Queries"> <break /> <example fontsize="1.6em" title=""><![CDATA[<?php /* Procedural Approach */ $db = sqlite_open("/path/to/database"); $result = sqlite_unbuffered_query("SELECT * FROM tbl", $db); /* OR */ $result = sqlite_unbuffered_query($db, "SELECT * FROM tbl"); ?>]]> </example> <example fontsize="1.6em" title=""><![CDATA[<?php /* Object Oriented Approach */ $db = new sqlite_db("/path/to/database"); $db->unbuffered_query("SELECT * FROM tbl"); ?>]]> </example> <list> <bullet>|00AA00|15-30% performance increase depending on the number of rows fetched.|</bullet> <bullet>|00AA00|Data is available right away, don't need to wait for all data to be pre-fetched.|</bullet> <bullet>|00AA00|Lower memory utilization.|</bullet> <bullet>|FF0000|Can only move forward one row at a time.|</bullet> </list> </slide> Index: presentations/slides/sqlite_jan/util2_oo.xml +++ presentations/slides/sqlite_jan/util2_oo.xml <slide title="SQLite Utility Methods II"> <blurb /> <example fontsize="1.6em" result="1" type="php" filename="utility2_oo.php" /> </slide> Index: presentations/slides/sqlite_jan/util3_oo.xml +++ presentations/slides/sqlite_jan/util3_oo.xml <slide title="SQLite Utility Methods III"> <blurb /> <example fontsize="1.6em" result="1" type="php" filename="utility3_oo.php" /> </slide> Index: presentations/slides/sqlite_jan/util_oo.xml +++ presentations/slides/sqlite_jan/util_oo.xml <slide title="SQLite Utility Methods"> <blurb /> <example fontsize="1.6em" result="1" type="php" filename="utility_oo.php" /> </slide> Index: presentations/slides/sqlite_jan/utility2_oo.php +++ presentations/slides/sqlite_jan/utility2_oo.php <?php $db = new sqlite_db(":memory:"); $db->query("CREATE TABLE foobar (id INTEGER PRIMARY KEY, misc CHAR(10))"); $db->query("INSERT INTO foobar (misc) VALUES('Marcus'); INSERT INTO foobar (misc) VALUES('Ilia')"); /* When performing multiple inserts within a single query * only the id of very last insert is returned */ echo "Last id: " . $db->last_insert_rowid() . "<br />\n"; echo '<pre>'; print_r($db->array_query("SELECT * FROM foobar", SQLITE_ASSOC)); echo '</pre>'; ?> Index: presentations/slides/sqlite_jan/utility3_oo.php +++ presentations/slides/sqlite_jan/utility3_oo.php <?php $db = new sqlite_db(":memory:"); $db->query("CREATE TABLE foobar (misc CHAR(10))"); $db->query("INSERT INTO foobar (misc) VALUES('Tall')"); $db->query(" INSERT INTO foobar (misc) VALUES('Wez'); INSERT INTO foobar (misc) VALUES('Marcus'); INSERT INTO foobar (misc) VALUES('Ilia'); UPDATE foobar SET misc='Tal' WHERE misc='Tall'; "); /* When chained queries are used rows changed returns the cumulative * of all rows affected by executed queries. */ echo "Number of affected rows: " . $db->changes() . " by chained query.<br />\n"; ?> Index: presentations/slides/sqlite_jan/utility_oo.php +++ presentations/slides/sqlite_jan/utility_oo.php <?php $db = new sqlite_db(dirname(__FILE__)."/db.sqlite"); $res = $db->query("SELECT * FROM auth_tbl"); /* return number of rows selected */ echo "Rows Fetched: " . $res->num_rows() . "<br />\n"; /* determine the number of columns in the result set */ echo "Columns per row " . ($n_cols = $res->num_fields()) . "<br />\n"; for ($i = 0; $i < $n_cols; $i++) { /* fetch column names */ echo "Column Names: " . $res->field_name($i) . "<br />\n"; } ?> Index: presentations/slides/perf_tunning/c_cflags.xml +++ presentations/slides/perf_tunning/c_cflags.xml <slide title="Compiling: CFLAGS"> <image filename="compiler.gif" align="right" /> <blurb fontsize="3em"> The first step to tuning PHP begins with compiling an optimized version of PHP. </blurb> <list fontsize="3em"> <bullet>Enable all compiler optimizations with %-O3%</bullet> <bullet>Make the compiler tune the code to your CPU via %-march% %-mcpu% |FF0000|Use Caution|</bullet> <bullet>Try to make the compiler use CPU specific features %-msse% %-mmmx% %-mfpmath=sse%</bullet> </list> <break lines="2" /> <example title="Revised Build Procedure" fontsize="1.4em"><![CDATA[ export CFLAGS="-O3 -msse -mmmx -march=pentium3 -mcpu=pentium3 -funroll-loops -mfpmath=sse" /configure make make install ]]></example> </slide> Index: presentations/slides/perf_tunning/c_exten.xml +++ presentations/slides/perf_tunning/c_exten.xml <slide title="Compile what you need"> <image filename="bloat.jpg" align="center" /> <blurb fontsize="4em"> Avoid useless bloat and compile only the extensions you need. </blurb> <blurb fontsize="4em"> Extensions that are rarely used, should be compiled as shared modules and loaded by the few scripts requiring them. </blurb> <blurb fontsize="4em"> %--disable-all% is your friend. </blurb> </slide> Index: presentations/slides/perf_tunning/c_static.xml +++ presentations/slides/perf_tunning/c_static.xml <slide title="Static vs Dynamic"> <blurb fontsize="4em"> For maximum performance compile PHP statically into apache (|00AA00|up to 20% speed increase|) </blurb> <example title="Static Compile of PHP" fontsize="2em"><![CDATA[ # PHP /configure --with-apache=/path/to/apache_source # Apache /configure --activate-module=src/modules/php4/libphp4.a ]]></example> <blurb> |FF0000|Increased speed comes at a cost of a slightly longer installation procedure, requiring Apache recompile every time PHP is upgraded.| </blurb> </slide> Index: presentations/slides/perf_tunning/c_strip.xml +++ presentations/slides/perf_tunning/c_strip.xml <slide title="Strip your binaries"> <blurb fontsize="4em"> Eliminate waste by removing symbols from object files using %strip% utility. </blurb> <image filename="strip.gif" align="center" /> <blurb fontsize="4em"> Saves disk space and more importantly memory needed to load the library or run the binary. In case of PHP makes the binary or Apache library |FF0000|20-30|% smaller. </blurb> </slide> Index: presentations/slides/perf_tunning/casting.php +++ presentations/slides/perf_tunning/casting.php <?php $_GET['n_entries'] = (int) $_GET['n_entries']; ?> Index: presentations/slides/perf_tunning/casting.xml +++ presentations/slides/perf_tunning/casting.xml <slide title="Type Conversion"> <blurb fontsize="4em"> PHP is a type less language, which can seamlessly manipulate variables containing any sort of data. </blurb> <blurb fontsize="3em"> However, forgetting about the underlying types can make your application slow and potentially open to security vulnerabilities. </blurb> <example title="Forcing correct type via casting" filename="casting.php" fontsize="1.4em" /> <blurb fontsize="3em"> Type conversion prevents things like SQL injection due to unexpected input. It also optimizes the application by providing PHP with a type it expects, rather having to internally perform type conversions each time the variable is used. </blurb> </slide> Index: presentations/slides/perf_tunning/conf_apache.xml +++ presentations/slides/perf_tunning/conf_apache.xml <slide title="Apache Configuration"> <image filename="apache.jpg" align="right" /> <blurb fontsize="4em"> Since the webserver plays an important part in the request serving process, it is important to tune it. A big part of this is the Apache child creation process. </blurb> <list fontsize="3.3em"> <bullet>%StartServers% set to avg. # of requests you'd expect.</bullet> <bullet>%MaxSpareServers% keep this number high, to allow Apache to gracefully handle traffic spikes.</bullet> <bullet>%MaxClients% keep this number at about 2/5 of the maximum processes your server can handle.</bullet> <bullet>%MaxRequestsPerChild% ideally unlimited (0), but practically should be limited to a large number.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/conf_apache2.xml +++ presentations/slides/perf_tunning/conf_apache2.xml <slide title="Apache Configuration Cont."> <image filename="apache.jpg" align="right" /> <list title="Reducing File IO" fontsize="4em"> <bullet>Keep %DirectoryIndex% file list as short as possible.</bullet> <bullet>Whenever possible disable .htaccess via %AllowOverride none%</bullet> <bullet>Use %Options FollowSymLinks% to simplify file access process in Apache</bullet> <bullet>Avoid using %mod_rewrite% or at least complex regexs</bullet> <bullet>If logs are unnecessary disable them.</bullet> <bullet>If logging is a must, log everything to 1 file, and break it up during analysis stage.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/conf_apache3.xml +++ presentations/slides/perf_tunning/conf_apache3.xml <slide title="Apache Configuration Cont."> <image filename="apache.jpg" align="right" /> <list title="Eliminate Expensive System Calls" fontsize="4em"> <bullet>Do not enable %ExtendedStatus% (prevents 2 calls to timing functions per request).</bullet> <bullet>For %Deny/Allow% rules use IPs rather then domains. (prevents superfluous DNS lookups).</bullet> <bullet>Do not enable %HostnameLookups% (DNS is slow).</bullet> <bullet fontsize="2em" marginleft="2em">This can be done during log analysis when speed is not an issue.</bullet> <bullet>Keep %ServerSignature% off (do not sent Apache identification string)</bullet> </list> </slide> Index: presentations/slides/perf_tunning/conf_php.xml +++ presentations/slides/perf_tunning/conf_php.xml <slide title="PHP Configuration (php.ini)"> <blurb fontsize="4em"> PHP configuration directives can have significant impact on performance of PHP applications. </blurb> <list fontsize="3.4em"> <bullet>Make sure that %register_globals% is disabled (default since 4.2.0)</bullet> <bullet>Disable %magic_quotes_*% directives.</bullet> <bullet fontsize="2em" marginleft="2em">|FF0000|make sure your applications will escape input when necessary|</bullet> <bullet>Turn off %expose_php%</bullet> <bullet>Turn off %register_argc_argv% for non-cli SAPIs</bullet> <bullet>Unless absolutely necessary do not enable %always_populate_raw_post_data%</bullet> </list> </slide> Index: presentations/slides/perf_tunning/conf_php2.xml +++ presentations/slides/perf_tunning/conf_php2.xml <slide title="PHP Configuration Cont."> <blurb fontsize="4em"> For non-persistent SAPIs like CLI prevent long searches for php.ini, by placing the file where PHP would look for it first. </blurb> <example title="PHP CLI"><![CDATA[/usr/local/lib/php-cli.ini]]></example> <example title="PHP CGI"><![CDATA[/usr/local/lib/php-cgi-fcgi.ini or /php-cgi-fcgi.ini]]></example> </slide> Index: presentations/slides/perf_tunning/content_caching.xml +++ presentations/slides/perf_tunning/content_caching.xml <slide title="Content Caching"> <blurb fontsize="3em"> Often enough output of PHP scripts can remain static for an extended period of time. In these cases, certain actions can be eliminated, resulting in a faster script execution. </blurb> <blurb title="Pre-generation" fontsize="3em"> When the content changes, generate static versions of the affected pages, taking PHP out of the equation completely. </blurb> <blurb title="On demand" fontsize="3em"> Same as pre-generation, only the content is not generated until the 1st request for the specified content arrives. </blurb> </slide> Index: presentations/slides/perf_tunning/content_caching_c.xml +++ presentations/slides/perf_tunning/content_caching_c.xml <slide title="Why is it better?"> <list fontsize="4em"> <bullet padding="0.5em">Faster (C is faster PHP).</bullet> <bullet padding="0.5em">Can easily store cache in memory or disk or both.</bullet> <bullet padding="0.5em">Better atomicity.</bullet> <bullet padding="0.5em">Supports zlib compression for cached pages.</bullet> <bullet padding="0.5em">Bypasses PHP completely.</bullet> <bullet padding="0.5em">No need to write/test/debug any code.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/content_caching_mmcache.xml +++ presentations/slides/perf_tunning/content_caching_mmcache.xml <slide title="Better Content Caching"> <blurb fontsize="4em"> As nice as PHP caching is, it is still slow, and who wants to spend time implementing it? </blurb> <blurb fontsize="3em"> Fortunately, both Zend and MMcache developers have realized this need and developed a content caching mechanism into their PHP acceleration packages. </blurb> <example fontsize="1.4em" filename="guestbook2.php" title="MMCache Content Cache" /> </slide> Index: presentations/slides/perf_tunning/content_caching_php.php +++ presentations/slides/perf_tunning/content_caching_php.php <?php function cache_start() { global $cache_file_name, $age; // a superbly creative way for creating cache files $cache_file_name = __FILE__ . '_cache'; // default cache age if (empty($age)) $age = 600; // check if cache exists and if the cached data is still valid if (@filemtime($cache_file_name) + $age > time()) { // Yey! cache hit, output cached data and exit readfile($cache_file_name); unset($cache_file_name); exit; } // nothing in cache or cache is too old ob_start(); } function cache_end() { global $cache_file_name; // nothing to do if (empty($cache_file_name)) return; // fetch output of the script $str = ob_get_clean(); // output data to the user, so they don't need to wait // for the cache writing to complete echo $str; // write to cache fwrite(fopen($cache_file_name.'_tmp', "w"), $str); // atomic write rename($cache_file_name.'_tmp', $cache_file_name); } cache_start(); // set cache termination code as the exit handler // this way we don't need to modify the script register_shutdown_function("cache_end"); ?> Index: presentations/slides/perf_tunning/content_caching_php.xml +++ presentations/slides/perf_tunning/content_caching_php.xml <slide title="Content Caching in PHP"> <example fontsize="1.4em" filename="content_caching_php.php" /> </slide> Index: presentations/slides/perf_tunning/content_caching_php2.xml +++ presentations/slides/perf_tunning/content_caching_php2.xml <slide title="Content Caching in PHP Cont."> <break /> <example fontsize="1.4em" filename="guestbook.php" /> <example fontsize="1.4em" title="Implementing cache without modifying the script"><![CDATA[# Add to .htaccess php_value auto_prepend_file "/path/to/cache.php" # Or to virtual host entry in httpd.conf php_admin_value auto_prepend_file "/path/to/cache.php"]]> </example> </slide> Index: presentations/slides/perf_tunning/content_compress.xml +++ presentations/slides/perf_tunning/content_compress.xml <slide title="Content Reduction"> <image filename="vice.gif" align="right" /> <blurb fontsize="4em"> One way to make pages appear faster is to reduce the amount of data that needs to be sent. </blurb> <break lines="2" /> <list fontsize="4em" title="Benefits of Content Reduction"> <bullet>Less data to send, leads to smaller bandwidth bill.</bullet> <bullet>Pages appear faster for the users, especially those on slower connections.</bullet> <bullet>Less network IO, frees up server processes faster.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/content_compress_css.xml +++ presentations/slides/perf_tunning/content_compress_css.xml <slide title="Content Reduction: CSS"> <image filename="vice.gif" align="right" /> <blurb fontsize="4em"> Another way to reduce content, is to replace bulky legacy HTML elements with CSS. </blurb> <list fontsize="3.6em" title="Advantages"> <bullet>20-30% smaller pages.</bullet> <bullet>CSS can be moved to static files and be served independently.</bullet> <bullet>In some cases makes the browser render page faster.</bullet> <bullet>More flexible layout.</bullet> </list> <list fontsize="3.6em" title="Disadvantages"> <bullet>Can be A LOT of manual labor.</bullet> <bullet>Older browsers (Netscape 4.0) do not support CSS.</bullet> <bullet>Some CSS is rendered differently or is unsupported all together.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/content_compress_tidy.xml +++ presentations/slides/perf_tunning/content_compress_tidy.xml <slide title="Content Reduction: Compacting"> <image filename="vice.gif" align="right" /> <blurb fontsize="3em"> HTML contains a large quantity of useless data such as whitespace, comments etc... that is normally used to make the output readable to the developers. </blurb> <blurb fontsize="3em"> In production no one other then the browser will be reading the HTML we can use the %tidy extension% to strip all the unnecessary bits. </blurb> <list fontsize="3.6em" title="Advantages"> <bullet>10-30% smaller pages.</bullet> <bullet>While compressing HTML can fix HTML bugs.</bullet> </list> <list fontsize="3.6em" title="Disadvantages"> <bullet>Requires Tidy extension.</bullet> <bullet>CPU costs make this useful only if the output is cached.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/content_compress_tidy2.xml +++ presentations/slides/perf_tunning/content_compress_tidy2.xml <slide title="Tidy Example"> <example title="Compacting Tidy Config" fontsize="1.4em"><![CDATA[indent: no hide-endtags: yes char-encoding: ascii word-2000: yes clean: yes bare: yes show-errors: 0 show-warnings: no quiet: yes drop-proprietary-attributes: yes hide-comments: yes wrap: 0]]></example> <break /> <example title="PHP script bit" fontsize="1.4em"><![CDATA[<?php ini_set("tidy.default_config", "/path/to/compact_tidy.cfg"); ini_set("tidy.clean_output", 1); ?>]]></example> </slide> Index: presentations/slides/perf_tunning/content_compress_zlib.xml +++ presentations/slides/perf_tunning/content_compress_zlib.xml <slide title="Content Reduction: Compression"> <image filename="vice.gif" align="right" /> <blurb fontsize="4em"> The easiest way to reduce amount of sent data is by compressing it. </blurb> <list fontsize="3.6em" title="Advantages"> <bullet>Text output drastically reduced.</bullet> <bullet>Requires no or very little modification to the code.</bullet> <bullet>Supported by majority of modern browsers.</bullet> </list> <list fontsize="3.6em" title="Disadvantages"> <bullet>May increase CPU load by up to 10%</bullet> <bullet>Some browsers claim to support it, but really don't.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/content_serve.xml +++ presentations/slides/perf_tunning/content_serve.xml <slide title="Optimizing Content Serving"> <blurb fontsize="4em"> Virtually any webpage is the combination of dynamic (php) and static content (images, CSS, JavaScript, etc...) </blurb> <blurb fontsize="4em"> For maximum performance it is best to separate the serving of dynamic and static content. </blurb> <list fontsize="3.6em" title="Benefits"> <bullet>Ability to disable KeepAlive for server handling dynamic data.</bullet> <bullet>Simpler and Faster serving numerous static requests.</bullet> <bullet>Allow more complex configuration (.htaccess, mod_rewrite) for dynamic data without affecting static content</bullet> <bullet>Easy distribution of the content serving load across servers.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/content_serve2.xml +++ presentations/slides/perf_tunning/content_serve2.xml <slide title="Static Content Web Servers"> <blurb fontsize="4em" title="Web Servers ideal for serving static requests" /> <break lines="2" /> <list fontsize="3.6em" title="TUX - kernel-based web server"> <bullet>Virtual Host support.</bullet> </list> <break lines="2" /> <list fontsize="3.6em" title="thttpd - tiny/turbo/throttling HTTP server"> <bullet>Non-blocking I/O is good.</bullet> <bullet>Throttling capabilities.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/guestbook.php +++ presentations/slides/perf_tunning/guestbook.php <?php require "./cache.php"; // our cache code // Simple guestbook script. $db = new sqlite_db("gb.sqlite"); $r = $db->array_query("SELECT * FROM guestbook", SQLITE_ASSOC); foreach ($r as $row) { echo $r->user . ' wrote on ' . date("Ymd", $r->date) . ":<br />\n"; echo $r->message . "<hr /><hr />"; } ?> Index: presentations/slides/perf_tunning/guestbook2.php +++ presentations/slides/perf_tunning/guestbook2.php <?php mmcache_cache_page(__FILE__, 600); // MMcache cache // Simple guestbook script. $db = new sqlite_db("gb.sqlite"); $r = $db->array_query("SELECT * FROM guestbook", SQLITE_ASSOC); foreach ($r as $row) { echo $r->user . ' wrote on ' . date("Ymd", $r->date) . ":<br />\n"; echo $r->message . "<hr /><hr />"; } ?> Index: presentations/slides/perf_tunning/includes.xml +++ presentations/slides/perf_tunning/includes.xml <slide title="File IO"> <blurb fontsize="4em"> Most PHP scripts perform File IO operations, whether it be inclusion of scripts or opening or writing to files. One common mistake made by developers often makes these operations much slower then necessary. </blurb> <example title="How NOT to open files" fontsize="4em"><![CDATA[<?php include "file.php"; ?>]]></example> </slide> Index: presentations/slides/perf_tunning/includes2.xml +++ presentations/slides/perf_tunning/includes2.xml <slide title="File IO Cont."> <blurb fontsize="4em"> Always use full path file path when opening files, to avoid expensive normalization of the file's path. </blurb> <example fontsize="4em"><![CDATA[<?php include "/path/to/file.php"; // or include "./file.php"; ?>]]></example> <blurb fontsize="4em"> This is very important even if you use opcode cache, since the paths of includes and normal files will still need to be resolved. </blurb> </slide> Index: presentations/slides/perf_tunning/join.php +++ presentations/slides/perf_tunning/join.php <?php // slow joinless approach $a = sqlite_fetch_single($db, "SELECT id FROM foo WHERE name='ilia'"); $b = sqlite_array_query($db, "SELECT * FROM bar WHERE id={$a}"); // Fast Join implementation $b = sqlite_array_query($db, "SELECT b.* FROM foo f INNER JOIN bar b ON f.id=b.id WHERE f.name='ilia'"); ?> Index: presentations/slides/perf_tunning/keep_alive.xml +++ presentations/slides/perf_tunning/keep_alive.xml <slide title="KeepAlive"> <blurb fontsize="4em"> In theory KeepAlive is supposed to make things faster, however if not used carefully it can cripple the server. </blurb> <list> <bullet>Set KeepAlive timeout, %KeepAliveTimeout% as low as possible.</bullet> </list> <image filename="ekg.jpg" align="center" /> <blurb fontsize="4em"> If the server is only serving dynamic requests, disable KeepAlive. </blurb> </slide> Index: presentations/slides/perf_tunning/lingerd.xml +++ presentations/slides/perf_tunning/lingerd.xml <slide title="lingerd"> <blurb> Lingerd is a daemon (service) designed to take over the job of properly closing network connections from an http server like Apache. </blurb> <break lines="2" /> <blurb> Because of some technical complications in the way TCP/IP and HTTP work, each Apache process currently wastes a lot of time "lingering" on client connections, after the page has been generated and sent. Lingerd takes over this job, leaving the Apache process immediately free to handle a new connection. As a result, Lingerd makes it possible to serve the same load using considerably fewer Apache processes. </blurb> <break lines="2" /> <blurb> |FF0000|Warning: will only work (properly) if KeepAlive is disabled.| </blurb> </slide> Index: presentations/slides/perf_tunning/opcode_benefits.xml +++ presentations/slides/perf_tunning/opcode_benefits.xml <slide title="OPcode Cache Benefits"> <list fontsize="4.5em"> <bullet padding="0.6em">Elimination of lexical parsing in most cases.</bullet> <bullet padding="0.6em">Significant reduction in FileIO.</bullet> <bullet padding="0.6em">Faster execution, thanks to optimized opcodes.</bullet> <bullet padding="0.6em">Elimination of certain function calls by the optimizer.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/opcode_comp.xml +++ presentations/slides/perf_tunning/opcode_comp.xml <slide title="Cache Benchmarks"> <break /> <image filename="opcode_bench.jpg" /> <image filename="opcode_bench2.jpg" /> <image filename="opcode_bench3.jpg" /> </slide> Index: presentations/slides/perf_tunning/opcode_graph.xml +++ presentations/slides/perf_tunning/opcode_graph.xml <slide title="OPcode Caching Cont."> <image filename="opcode_cache.png" align="center" /> </slide> Index: presentations/slides/perf_tunning/opcode_imp.xml +++ presentations/slides/perf_tunning/opcode_imp.xml <slide title="Cache Implementations"> <list fontsize="3.4em"> <bullet>Turck MMCache (GPL)</bullet> <bullet marginleft="2em">|00AA00|Implements many features beyond opcode caching.|</bullet> <bullet marginleft="2em">|FF0000|Development halted.|</bullet> <bullet>APC (PHP)</bullet> <bullet marginleft="2em">|00AA00|Slow, but steady progress.|</bullet> <bullet marginleft="2em">|FF0000|Weak optimizer.|</bullet> <bullet>ionCube PHP Accelerator</bullet> <bullet marginleft="2em">|FF0000|It works, but no new development in past year.|</bullet> <bullet marginleft="2em">|00AA00|Free|, but |FF0000|closed source|.</bullet> <bullet>Zend Cache (Proprietary)</bullet> <bullet marginleft="2em">|00AA00|Implements many features beyond opcode caching.|</bullet> <bullet marginleft="2em">|FF0000|$$$|</bullet> </list> </slide> Index: presentations/slides/perf_tunning/opcode_intro.xml +++ presentations/slides/perf_tunning/opcode_intro.xml <slide title="OPcode Caching"> <blurb fontsize="4em"> Before even trying to execute a script, it needs to converted into a series instructions (opcodes) that the Zend Engine can understand and execute. </blurb> <image filename="cache.jpg" align="center" /> <blurb fontsize="4em"> Since scripts rarely change, an obvious optimization is to cache the opcodes so that the scripts need not be parsed every time. </blurb> </slide> Index: presentations/slides/perf_tunning/partial_caching.xml +++ presentations/slides/perf_tunning/partial_caching.xml <slide title="Partial Caching"> <blurb fontsize="4em"> I'd like to use caching, but my content is completely dynamic and cannot be time delayed. </blurb> <break lines="2" /> <blurb align="center" fontsize="4em">|FF0000| LIES! LIES! LIES!|</blurb> <break lines="2" /> <blurb fontsize="4em"> Even the most dynamic pages, often have static elements generated by PHP. Partial caching can accelerate the page generation by caching the static portions of otherwise dynamic pages. </blurb> </slide> Index: presentations/slides/perf_tunning/partial_caching_ex.php +++ presentations/slides/perf_tunning/partial_caching_ex.php <?php // Authenticates a user and stores their id inside $uid require "./user_auth.inc.php"; function header() { if ($uid) echo "Welcome {$GLOBALS['user_nick']}"; echo rest_of_header(); } function footer() { if ($uid) echo "Logout: <a href='/logout.php'>{$GLOBALS['user_nick']}</a>"; echo rest_of_footer(); } // cache the output of the header function // we append $uid to they key to ensure each user has their own // non conflicting entry. mmcache_cache_output(__FILE__ . $uid, 'header();', 60 * 24); // rest of the dynamic page // cache the output of the footer for 24 minutes (avg. session length) mmcache_cache_output(__FILE__ . $uid, 'footer();', 60 * 24); ?> Index: presentations/slides/perf_tunning/partial_caching_ex.xml +++ presentations/slides/perf_tunning/partial_caching_ex.xml <slide title="Partial Caching in Action"> <example filename="partial_caching_ex.php" fontsize="1.4em" /> </slide> Index: presentations/slides/perf_tunning/query_chain.php +++ presentations/slides/perf_tunning/query_chain.php <?php // Slow Approach for ($i = 0; $i < 10; $i++) mysql_query("INSERT INTO foo VALUES({$i})"); // Faster MySQL/SQLite Specific approach $query = "INSERT INTO foo VALUES"; $query = "(" . implode("),(", array_keys(array_fill(0, 10, 1))) . ")"; // INSERT INTO foo VALUES (0), (1), (2) ... mysql_query($query); // Query Chaining // for DBs that support it PostgreSQL, MSSQL, SQLite, MySQL 4.0+ $query = ''; for ($i = 0; $i < 10; $i++) $query .= "INSERT INTO foo VALUES({$i});"; mysql_query($query); ?> Index: presentations/slides/perf_tunning/references.xml +++ presentations/slides/perf_tunning/references.xml <slide title="References Tricks"> <example fontsize="1.4em" title="Optimize passing of large objects by passing them by reference (PHP 4)."><![CDATA[<?php function display_function(&$obj) { ... } $obj = mysql_fetch_object($result); display_function($obj); ?>]]></example> <example fontsize="1.4em" title="When modifying complex or large variables inside a function/method."><![CDATA[<?php function template_apply(&$str) { $str = str_replace(..., ..., $str); } ?>]]></example> <example fontsize="1.4em" title="Simplify and Speed up access to large multi-dimensional arrays"><![CDATA[<?php $foo =& $bar['foo']['bar']['test']; $foo['imp'] = implode(',', $foo); $foo['imp'] = addslashes($foo['imp']); ?>]]></example> </slide> Index: presentations/slides/perf_tunning/regex.xml +++ presentations/slides/perf_tunning/regex.xml <slide title="Regular Expressions"> <blurb fontsize="4em"> PHP being is often using for templating and as such often needs to manipulate strings, which is often done with Regular Expressions. </blurb> <image filename="regex.jpg" align="center" /> <blurb fontsize="4em"> Unfortunately, the flexibility that makes regular expressions so useful, also makes them extremely slow. </blurb> </slide> Index: presentations/slides/perf_tunning/regex2.xml +++ presentations/slides/perf_tunning/regex2.xml <slide title="Regular Expressions Cont."> <image filename="regex.jpg" align="right" /> <blurb fontsize="4em"> Significant speed gains can be made by replacing regular expression with one or more string functions offered by PHP. </blurb> <list title="Common Alternatives" fontsize="4em"> <bullet>Replacement - %str_replace%, %substr_replace%, %strtr%, etc...</bullet> <bullet>Matching - %strpos%, %stripos%, %strchr%, %strrchr%, etc..</bullet> <bullet>Type Checking - %ctype% extension (enabled by default)</bullet> <bullet>Comparison - %strcmp%, %strncasecmp%, etc...</bullet> </list> </slide> Index: presentations/slides/perf_tunning/regex3.xml +++ presentations/slides/perf_tunning/regex3.xml <slide title="Regular Expressions Cont."> <image filename="regex.jpg" align="right" /> <blurb fontsize="4em"> In some situations, regular expressions would take too long to replace. Now you need to decide which regular expression implementation you want %ereg% or %PCRE%. </blurb> <list type="Implementation Comparison" fontsize="3.6em"> <bullet>PCRE</bullet> <bullet marginleft="2em">Much faster in most cases.</bullet> <bullet marginleft="2em">UTF-8 support.</bullet> <bullet marginleft="2em">Significantly greater functionality.</bullet> <bullet>ereg</bullet> <bullet marginleft="2em">Always available.</bullet> <bullet marginleft="2em">Can operate on multi-byte strings w/mbstring extension.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/right_db.xml +++ presentations/slides/perf_tunning/right_db.xml <slide title="SQL: Right Tool for the Job"> <image filename="postgresql.gif" align="right" /> <blurb fontsize="4em"> It is important that you choose the %right% database system for your needs. </blurb> <break lines="2" /> <image filename="oracle.gif" align="right" /> <blurb fontsize="4em"> An overly complex database system, who's features you do not use will only hinder performance. </blurb> <break lines="2" /> <image filename="mysql.gif" align="right" /> <blurb fontsize="4em"> At the same time be cautious with overly simple database systems that lack features you may need. </blurb> </slide> Index: presentations/slides/perf_tunning/sessions.xml +++ presentations/slides/perf_tunning/sessions.xml <slide title="Sessions"> <blurb fontsize="4em"> Common element of various PHP scripts are sessions. </blurb> <list title="Generic Session Optimizations" fontsize="3.6em"> <bullet>Don't use %session.auto_start%.</bullet> <bullet>Do not enable %session.use_trans_sid%</bullet> <bullet>Whenever possible set %session.cache_limiter% to %private_no_expire%</bullet> <bullet>Assign each user (vhost) it's own sessions directory.</bullet> <bullet>For large sites consider using %session.save_path = "N;/path"%</bullet> <bullet>If possible avoid automatic garbage collection.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/sessions2.xml +++ presentations/slides/perf_tunning/sessions2.xml <slide title="Sessions Cont."> <blurb fontsize="3em"> The surest way to accelerate sessions is by moving away from the %files% session handler to a memory based one. </blurb> <list fontsize="3.6em" title="Memory Session Handlers"> <bullet>tmpfs</bullet> <bullet marginleft="2em">mount the session directory as a RAM disk.</bullet> <bullet marginleft="2em">|FF0000|not available on all OSes|</bullet> <bullet>--with-mm</bullet> <bullet marginleft="2em">available with every PHP version.</bullet> <bullet marginleft="2em">|FF0000|not thread-safe|</bullet> <bullet>mmcache</bullet> <bullet marginleft="2em">very fast</bullet> <bullet marginleft="2em">work on virtually all OSes and is thread-safe</bullet> <bullet marginleft="2em">|FF0000|you need mmcache|</bullet> </list> </slide> Index: presentations/slides/perf_tunning/sql_chain.xml +++ presentations/slides/perf_tunning/sql_chain.xml <slide title="SQL: Query Chaining"> <image filename="database_sm.gif" align="right" /> <blurb fontsize="4em"> Executing one query at a time is boring (and slow), chain them and execute many queries at once. </blurb> <example title="Query Chaining" fontsize="1.4em" filename="query_chain.php" /> </slide> Index: presentations/slides/perf_tunning/sql_explain.xml +++ presentations/slides/perf_tunning/sql_explain.xml <slide title="SQL: Explain"> <image filename="database_sm.gif" align="right" /> <blurb fontsize="4em"> Always use %EXPLAIN% to analyze your queries to determine if they use proper indexes. </blurb> <example fontsize="1.4em" title="Slow Query"><![CDATA[ EXPLAIN select * from mm_users where login LIKE '%ilia%'; +----------+------+---------------+------+---------+------+-------+------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +----------+------+---------------+------+---------+------+-------+------------+ | mm_users | ALL | NULL | NULL | NULL | NULL | 27506 | where used | +----------+------+---------------+------+---------+------+-------+------------+ ]]></example> <example fontsize="1.4em" title="Fast Query"><![CDATA[ EXPLAIN select * from mm_users where login LIKE 'ilia%'; +----------+-------+---------------+-------+---------+------+------+------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +----------+-------+---------------+-------+---------+------+------+------------+ | mm_users | range | login | login | 50 | NULL | 2 | where used | +----------+-------+---------------+-------+---------+------+------+------------+ ]]></example> </slide> Index: presentations/slides/perf_tunning/sql_intro.xml +++ presentations/slides/perf_tunning/sql_intro.xml <slide title="SQL"> <image filename="database.gif" align="right" /> <blurb fontsize="4em"> Virtually every script uses some database system. How it is used can be the difference between a fast script and an extremely slow one. </blurb> <break lines="4" /> <blurb fontsize="4em"> All optimizations can be for naught if the SQL queries executed are slow. </blurb> </slide> Index: presentations/slides/perf_tunning/sql_join.xml +++ presentations/slides/perf_tunning/sql_join.xml <slide title="SQL: Joins"> <image filename="database_sm.gif" align="right" /> <blurb fontsize="4em"> Usage of joins allows simplification &amp; acceleration of the script by moving portions of the logic to the database engine. </blurb> <example filename="join.php" fontsize="1.4em" /> <list title="Join Gotchas" fontsize="3em"> <bullet>Unoptimized joins can be VERY slow.</bullet> <bullet>Internal (read) lock on all tables involved.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/sql_locks.xml +++ presentations/slides/perf_tunning/sql_locks.xml <slide title="SQL: Avoiding Locks"> <image filename="database_sm.gif" align="right" /> <blurb fontsize="4em"> To ensure data integrity in certain situations you will need to use locks. However, overuse of locks or improper implementation can severely hinder the performance of your application. </blurb> <list fontsize="3.2em"> <bullet>If supported, when possible use row level locks instead of table locks.</bullet> <bullet>When using table locks, try to have the effect as few tables as possible.</bullet> <bullet>Whenever possible avoid locks all together.</bullet> </list> </slide> Index: presentations/slides/perf_tunning/sql_mysql4.xml +++ presentations/slides/perf_tunning/sql_mysql4.xml <slide title="SQL: MySQL 4.0"> <image filename="database_sm.gif" align="right" /> <blurb fontsize="4em"> If you are using MySQL, definitely consider switching to MySQL 4.0. </blurb> <list fontsize="4em" title="Performance Advantages"> <bullet>Query Cache</bullet> <bullet>Sub-Queries (as of 4.0.4)</bullet> <bullet>Faster bulk inserts</bullet> <bullet>Improved %FULLTEXT%</bullet> </list> </slide> Index: presentations/slides/perf_tunning/sql_subquery.xml +++ presentations/slides/perf_tunning/sql_subquery.xml <slide title="SQL: Sub-queries"> <image filename="database_sm.gif" align="right" /> <blurb fontsize="4em"> Like Joins, Sub-queries can be used to move some of the logic from PHP into the database engine. </blurb> <example filename="subquery.php" fontsize="1.4em" /> <blurb fontsize="4em"> In MySQL, the full support for sub-queries starts from version 4.1 </blurb> <blurb fontsize="4em"> In many instances it is better to use Joins rather then sub-queries. </blurb> </slide> Index: presentations/slides/perf_tunning/sql_tmp_tbl.xml +++ presentations/slides/perf_tunning/sql_tmp_tbl.xml <slide title="SQL: Temporary Tables"> <image filename="database_sm.gif" align="right" /> <blurb fontsize="4em"> Temporary tables are memory buffers that can be used as in between steps for data retrieval, to avoid complex (and slow) PHP logic. </blurb> <example fontsize="1.4em" filename="tmp_table.php" /> </slide> Index: presentations/slides/perf_tunning/subquery.php +++ presentations/slides/perf_tunning/subquery.php <?php $b = sqlite_array_query($db, "SELECT * FROM bar WHERE id=(SELECT id FROM foo WHERE name='ilia')"); ?> Index: presentations/slides/perf_tunning/thankyou.xml +++ presentations/slides/perf_tunning/thankyou.xml <slide title="Thank You" fontsize="6em"> <blurb title="Online Resources" /> <break /> <link fontsize="2em" marginleft="2em" leader="Turck MMcache: ">http://sourceforge.net/projects/turck-mmcache/</link> <link fontsize="2em" marginleft="2em" leader="APC: ">http://pecl.php.net/apc</link> <link fontsize="2em" marginleft="2em" leader="Zend: ">http://www.zend.com</link> <link fontsize="2em" marginleft="2em" leader="lingerd: ">htpp://www.iagora.com/about/software/lingerd/</link> <link fontsize="2em" marginleft="2em" leader="thttpd: ">http://www.acme.com/software/thttpd/</link> <break lines="2" /> <blurb title="Contact Me" /> <link fontsize="2.5em" marginleft="2em" leader="Ilia Alshanetsky ">ilia@php.net</link> </slide> Index: presentations/slides/perf_tunning/titlepage.xml +++ presentations/slides/perf_tunning/titlepage.xml <slide template="titlepage" fontsize="6em"> <title>Welcome!</title> </slide> Index: presentations/slides/perf_tunning/tmp_table.php +++ presentations/slides/perf_tunning/tmp_table.php <?php // Quickly fetch the ids of needed messages mysql_query("CREATE TEMPORARY TABLE mtmp AS SELECT id FROM msg WHERE thread_id={$_GET['th']} AND apr=1 ORDER BY id ASC LIMIT {$count}, {$_GET['start']}"); // Retrieve needed data by using the temporary table as base $result = mysql_query("SELECT * FROM mtmp mt INNER JOIN msg m ON m.id=mt.id INNER JOIN thread t ON m.thread_id=t.id INNER JOIN forum f ON t.forum_id=f.id LEFT JOIN users u ON m.poster_id=u.id LEFT JOIN level l ON u.level_id=l.id LEFT JOIN poll p ON m.poll_id=p.id LEFT JOIN poll_opt_track pot ON pot.poll_id=p.id AND pot.user_id="._uid." ORDER BY m.id ASC"); ?> Index: presentations/slides/perf_tunning/tmpfs.xml +++ presentations/slides/perf_tunning/tmpfs.xml <slide title="RAM Disk"> <blurb fontsize="4em"> One way to accelerate File IO operations is by moving the files to a RAM disk. </blurb> <blurb fontsize="4em"> On Linux this is extremely simple todo using via %tmpfs%. </blurb> <example title="tmpfs acceleration"><![CDATA[# Speed Up /tmp Directory mount --bind -ttmpfs /tmp /tmp # Accelerate Scripts Directory mount --bind -ttmpfs /home/webroot /home/webroot]]></example> </slide> Index: presentations/slides/perf_tunning/tmpfs2.xml +++ presentations/slides/perf_tunning/tmpfs2.xml <slide title="RAM Disk Cont."> <list title="Advantages" fontsize="4em"> <bullet>Significant improvement in all File IO operations.</bullet> <bullet>Easy to use.</bullet> </list> <list title="Disadvantages" fontsize="4em"> <bullet>Can end up using A LOT of memory.</bullet> </list> </slide>
« previous php.pres (#932) next »