php
play

PHP Apachecon Dec.14, 2005. San Diego Rasmus Lerdorf - PDF document

PHP Apachecon Dec.14, 2005. San Diego Rasmus Lerdorf <rasmus@php.net> http://talks.lerdorf.com/show/acon05 Slide 1/26 November 17 2005 Server-Side PHP is a Server-side language Even though it is embedded in HTML files much like the


  1. PHP Apachecon Dec.14, 2005. San Diego Rasmus Lerdorf <rasmus@php.net> http://talks.lerdorf.com/show/acon05

  2. Slide 1/26 November 17 2005 Server-Side PHP is a Server-side language Even though it is embedded in HTML files much like the client-side Javascript language, PHP is server-side and all PHP tags will be replaced by the server before anything is sent to the web browser. � So if the HTML file contains: � <html> <?php echo "Hello World" ?> </html> What the end user would see with a "view source" in the browser would be: � <html> Hello World </html> - 2 -

  3. Slide 2/26 November 17 2005 Idea This is a C program that generates an HTML page with a table populated from an SQL query. � #include <stdio.h> #include <stdlib.h> #include "mysql.h" MYSQL mysql; void err(void) { fprintf(stderr, "%s\n", mysql_error(&mysql) ); exit(1); } int gen_page() { puts("<html><body><table>"); if(!(mysql_connect(&mysql,"host","user","passwd"))) err(); if(mysql_select_db(&mysql,"my_db")) err(); if(mysql_query(&mysql,"SELECT * FROM my_table")) err(); if(!(res = mysql_store_result(&mysql))) err(); while((row = mysql_fetch_row(res))) { puts("<tr>"); for (i=0 ; i < mysql_num_fields(res); i++) printf("<td>%s</td>\n",row[i]); puts("</tr>"); } puts("</table></body></html>"); if (!mysql_eof(res)) err(); mysql_free_result(res); mysql_close(&mysql); } Here is the same thing in PHP which produces the same output. � <html><body><table> <?php mysql_connect('host','user','passwd') or die(mysql_error()); $res = mysql_db_query('my_db','SELECT * FROM my_table') or die(mysql_error()); while(($row = mysql_fetch_row($res))) { echo '<tr>'; for ($i=0 ; $i < mysql_num_fields($res); $i++) echo "<td>{$row[$i]}</td>\n"; echo '</tr>'; } ?> </table></body></html> - 3 -

  4. Slide 3/26 November 17 2005 Fail Fast! Fail Fast � Fail Cheap � Be Lazy � The greatest inefficiencies come from solving problems you will never have. � - 4 -

  5. Slide 4/26 November 17 2005 What is Large? o 75 properties � o 25 international portals � o 15 Languages � o Hundreds of millions of registered users � o Literally billions of page views per day � o Thousands of engineers spread around the world � Merger of 24 Web Companies � Make that 30 now with FareChase, MusicMatch, Flickr, DialPad, Konfabulator and Upcoming.org � - 5 -

  6. Slide 5/26 November 17 2005 Why PHP? � o Easy to learn and manage - well-documented � o Works well on existing FreeBSD/Apache platform � o Easy to integrate existing C/C++ code � o Inherent HTML embedding � o Outperformed technologies it replaced � - 6 -

  7. Slide 6/26 November 17 2005 Scale � Share-nothing Architecture o Like HTTP, each request is distinct � o Shared data is pushed down to the data-store layer � This gives us o Ability to load balance � o Invisible failover from one datacenter to another � o Better modularization of applications � o Easier to develop and debug � - 7 -

  8. Slide 7/26 November 17 2005 Scale No Runtime Templating! o PHP is a templating system, we don't need another one � o Ok, sometimes you might, but don't do it at runtime � System Calls - PHP 5.1 Code Changes o No more than 1 stat() per PHP file per request � o Add a stat cache to PHP's expand_filepath code � o Don't stat if Apache has already stat'ed the file � o Get rid of excessive stats in the streams code � System Calls - Scripting Changes o Remove ./ from include_path and use relative path includes � o Use just a single base dir in include_path � o No open_basedir or safe_mode � - 8 -

  9. Slide 8/26 November 17 2005 Scale Watch those compiler flags o Use non-PIC Apache DSO (gcc -prefer-non-pic) by using --without-pic � o Use platform-specific gcc flags � o ./configure --disable-all � Other Changes o Plenty of custom extensions and limit RINIT � o Filter all user data by default � o No $_COOKIE nor $_ENV for you and use JIT population for $_SERVER � o Careful use of the session extension � - 9 -

  10. Slide 9/26 November 17 2005 Software Stack � o FreeBSD 4.x/6.x � o Apache 1.3.x � o Plenty of homegrown C/C++ code � o MySQL/Oracle � o PHP/Perl � o APC Opcode Cache � - 10 -

  11. Slide 10/26 November 17 2005 People Architecture � - 11 -

  12. Slide 11/26 November 17 2005 App Architecture A suggested architecture for a PHP application. The template layer should have as little business logic as possible. As you go down you have less presentation and more business logic. � - 12 -

  13. Slide 12/26 November 17 2005 Large-Scale PHP Scaling PHP is all about scaling your backend � Or bigger � Debugging and Profiling, look at xdebug (xdebug.org) and apd (pecl/apd) � - 13 -

  14. - 14 -

  15. Slide 13/26 November 17 2005 PHP 5 PHP 5 � - 15 -

  16. Slide 14/26 November 17 2005 XML All XML handling based on libxml2 <?php $dom = new domDocument; $dom->load('menu.xml'); ?> presentations/slides/intro/menu.xml &lt;?xml&nbsp;version=&quot;1.0&quot;&nbsp;encoding=&quot;ISO-8859-1&quot;?&gt;� &lt;breakfast_menu&gt;� &nbsp;&lt;food&nbsp;itemno=&quot;1&quot;&gt;� &nbsp;&nbsp;&lt;name&gt;Belgian&nbsp;Waffles&lt;/name&gt;� &nbsp;&nbsp;&lt;price&gt;$5.95&lt;/price&gt;� &nbsp;&nbsp;&lt;description&gt;two&nbsp;of&nbsp;our&nbsp;famous&nbsp;Belgian&nbsp;Waffles&nbsp;with&nbsp;� &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;plenty&nbsp;of&nbsp;real&nbsp;maple&nbsp;syrup&lt;/description&gt;� &nbsp;&nbsp;&lt;calories&gt;650&lt;/calories&gt;� &nbsp;&lt;/food&gt;� &nbsp;&lt;food&nbsp;itemno=&quot;2&quot;&gt;� &nbsp;&nbsp;&lt;name&gt;Strawberry&nbsp;Belgian&nbsp;Waffles&lt;/name&gt;� &nbsp;&nbsp;&lt;price&gt;$7.95&lt;/price&gt;� &nbsp;&nbsp;&lt;description&gt;light&nbsp;Belgian&nbsp;waffles&nbsp;covered&nbsp;with&nbsp;strawberries� &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and&nbsp;whipped&nbsp;cream&lt;/description&gt;� &nbsp;&nbsp;&lt;calories&gt;900&lt;/calories&gt;� &nbsp;&lt;/food&gt;� &nbsp;&lt;food&nbsp;itemno=&quot;3&quot;&gt;� &nbsp;&nbsp;&lt;name&gt;Berry-Berry&nbsp;Belgian&nbsp;Waffles&lt;/name&gt;� &nbsp;&nbsp;&lt;price&gt;$8.95&lt;/price&gt;� &nbsp;&nbsp;&lt;description&gt;light&nbsp;Belgian&nbsp;waffles&nbsp;covered&nbsp;with&nbsp;an&nbsp;assortment&nbsp;of� &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fresh&nbsp;berries&nbsp;and&nbsp;whipped&nbsp;cream&lt;/description&gt;� &nbsp;&nbsp;&lt;calories&gt;900&lt;/calories&gt;� &nbsp;&lt;/food&gt;� &nbsp;&lt;food&nbsp;itemno=&quot;4&quot;&gt;� &nbsp;&nbsp;&lt;name&gt;French&nbsp;Toast&lt;/name&gt;� &nbsp;&nbsp;&lt;price&gt;$4.50&lt;/price&gt;� &nbsp;&nbsp;&lt;description&gt;thick&nbsp;slices&nbsp;made&nbsp;from&nbsp;our&nbsp;homemade&nbsp;sourdough&nbsp;bread&lt;/description&gt;� &nbsp;&nbsp;&lt;calories&gt;600&lt;/calories&gt;� &nbsp;&lt;/food&gt;� - 16 -

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend