Php at Yahoo Zend2005

of 26

  • date post

    29-May-2018
  • Category

    Documents

  • view

    218
  • download

    0

Embed Size (px)

Transcript of Php at Yahoo Zend2005

  • 8/8/2019 Php at Yahoo Zend2005

    1/26

    1

    PHP at Yahoo!http://public.yahoo.com/~radwin/

    Michael J. Radwin

    October 20, 2005

  • 8/8/2019 Php at Yahoo Zend2005

    2/26

    2

    Outline

    Yahoo!, as seen by an engineer

    Choosing PHP in 2002

    PHP architecture at Yahoo!

  • 8/8/2019 Php at Yahoo Zend2005

    3/26

    3

    The Internets most trafficked site

  • 8/8/2019 Php at Yahoo Zend2005

    4/26

  • 8/8/2019 Php at Yahoo Zend2005

    5/26

    5

    Yahoo! by the Numbers

    411M unique visitors per month

    191M active registered users

    11.4M fee-paying customers

    3.4B average daily pageviews

    October 2005

  • 8/8/2019 Php at Yahoo Zend2005

    6/26

    6

  • 8/8/2019 Php at Yahoo Zend2005

    7/26

    7

    Engineering Values

    1. Security & Privacy

    We must protect our customers information

    2. High Availability

    If the site is offline, were missing the opportunityto serve our customers

    3. Performance

    We serve billions of pageviews a day

    4. Flexibility & Innovation

    Customize site for each market

    Rapid development of new features

  • 8/8/2019 Php at Yahoo Zend2005

    8/26

    8

    From Proprietary to Open Source

    94 95 96 97 98 99 00 01 02 03 04 05

    Web

    Server Apache

    Filo Server

    Web

    Lang

    yScript

    DB

    Flat Files

  • 8/8/2019 Php at Yahoo Zend2005

    9/26

    9

    Choosing a Language

    How and Why We Selected PHP

  • 8/8/2019 Php at Yahoo Zend2005

    10/26

    10

    Choosing PHP: brief history

    October 2001: 3 proprietary languages

    Costly to continue to maintain each

    Limited features (no subroutines!)

    Committee began researching

    Compare features, performance

    Build vs. Buy vs. Open Source

    PHP selected May 2002

  • 8/8/2019 Php at Yahoo Zend2005

    11/26

    11

    Ideal Language Criteria

    1. High performance

    2. Robust, sand-boxed

    3. Language features Loops, conditionals

    Complex data-types

    4. C/C++ extensions

    5. Runs on FreeBSD

    8. Interpreted or

    dynamically compiled

    9. i18n support

    10. Clean separation of

    presentation/content/

    app semantics

    11. Low training costs

    12. Doesnt require CS

    degree to use

  • 8/8/2019 Php at Yahoo Zend2005

    12/26

    12

    Top 10 Language Choices

    mod_include

    XSLT

    yScript

  • 8/8/2019 Php at Yahoo Zend2005

    13/26

    13

    Performance: Requests

    Requests/sec

    0

    50

    100

    150

    200

    250

    300

    350

    25 50 75 100 150 200 300 400 500

    Concurrent requests

    req/s

    PHP

    YSP

    HF2k

    Network max

    mod_perl

    yScript

  • 8/8/2019 Php at Yahoo Zend2005

    14/26

    14

    Performance: Memory

    Active Virtual Memory

    0

    200000

    400000

    600000

    800000

    1000000

    25 50 75 100 150 200 300 400 500

    Concurrent requests

    kbytes

    active

    PHP

    YSP

    HF2k

    mod_perl

    yScript

  • 8/8/2019 Php at Yahoo Zend2005

    15/26

    15

    Why we picked PHP

    1. Designed for web scripting

    2. High performance

    3. Large, Open Source community

    Documentation, easy to hire developers

    4. Code-in-HTML paradigm

    5. Integration, libraries, extensibility

    6. Tools: IDE, debugger, profiler

  • 8/8/2019 Php at Yahoo Zend2005

    16/26

  • 8/8/2019 Php at Yahoo Zend2005

    17/26

    17

    Yahoo!s Development Methodology

    Server Architecture

    File Layout

    Dependency Management

    Security

    Performance Globalization

  • 8/8/2019 Php at Yahoo Zend2005

    18/26

    18

    User

    Profile

    Server

    web server

    Server Architecture

    web serverWeb Server

    Scripts

    Lo

    ad

    Balancer

    Ad

    Server

    Web

    ServicesApache

  • 8/8/2019 Php at Yahoo Zend2005

    19/26

    19

    File Layout

    HTML Templates/usr/local/share/htdocs/*.php

    Template Helpers/usr/local/share/htdocs/*.inc

    Business Logic/usr/local/share/pear/*.inc

    C/C++ Core CodeData access, Networking, Crypto

    50% HTML

    50% PHP

    0% HTML

    100% PHP

    0% HTML

    0% PHP

    95% HTML

    5% PHP

  • 8/8/2019 Php at Yahoo Zend2005

    20/26

    20

    Dependency Management

    Base PHP package depends only onXML parser

    ./configure --disable-all

    Self-Contained Extensions

    mysql, dba, curl, ldap, pcre, gd, iconv

    To enable

    1. Install/usr/local/lib/php/20020429/mysql.so

    2. Add extension = mysql.so tophp.ini

    Avoids unnecessary dependencies

    Smaller Apache memory footprint

  • 8/8/2019 Php at Yahoo Zend2005

    21/26

    21

    Security: INI Settings

    open_basedir

    Insurance against /etc/passwd exploits

    allow_url_fopen = Off

    Use libcurl extension instead

    Avoid open proxy exploits

    display_errors = Off

    However, log_errors = On

    safe_mode = Off

    Intended for shared hosting environment

  • 8/8/2019 Php at Yahoo Zend2005

    22/26

    22

    Security: Input Filtering

    http://search.yahoo.com/search?p=

    Cross Site Scripting (XSS) most common attack

    Also SQL Injection

    Normal approach strip_tags()

    mysqli_escape_string()

    Examine every line code

    Tedious and error-prone

    Use input_filter hook

    Sanitize all user-submitted data

    GET/POST/Cookie

  • 8/8/2019 Php at Yahoo Zend2005

    23/26

    23

    Performance: Opcode Caches

    Easiest performance boost

    Cache parsed .php scriptsin shared memory

    Optimizations

    No code modifications!

    Several products available

    Zend Performance Suite

    APC

    Turck MMCache

  • 8/8/2019 Php at Yahoo Zend2005

    24/26

    24

    Performance: PHP Extensions in C++

    PHP ships with 80

    extensions written in C/C++

    Yahoo! develops its own

    proprietary extensions

    Fast execution speed

    Access to client libraries

    Longer development cycle Edit, compile, link, debug

    Manual memory-

    management

  • 8/8/2019 Php at Yahoo Zend2005

    25/26

  • 8/8/2019 Php at Yahoo Zend2005

    26/26

    26