Developing Web Applications with Perl, memcached, MySQL® and Apache

Book description

The only book to address using cache to enhance and speed up Web application development

  • Developers use Apache, MySQL, memcached, and Perl to build dynamic Web sites that store information within the MySQL database; this is the only book to address using these technologies together to alleviate the database load in Web development

  • Covers each of the four systems and shows how to install, set up, and administer them; then shows the reader how to put the parts together to start building applications

  • Explains the benefits of a base perl library for code re-use, and provides sample applications that demonstrate in a practical way the information covered in the previous chapters

  • Examines monitoring, performance, and security, with a problem-solving chapter that walks the reader through solving real-world issues

Table of contents

  1. Copyright
  2. Credits
  3. About the Author
  4. About the Technical Editor
  5. Acknowledgments
  6. Foreword
  7. Introduction
    1. Who This Book Is For
    2. What This Book Covers
    3. How This Book Is Structured
    4. What You Need to Use This Book
    5. Conventions
    6. Source Code
    7. Errata
    8. p2p.wrox.com
  8. 1. LAMMP, Now with an Extra M
    1. 1.1. Linux
    2. 1.2. Apache
    3. 1.3. MySQL
    4. 1.4. memcached
      1. 1.4.1. Gear6
      2. 1.4.2. Clickability
      3. 1.4.3. GaiaOnline
      4. 1.4.4. How memcached Can Work for You
    5. 1.5. Perl
    6. 1.6. Other Technologies
      1. 1.6.1. Sphinx
      2. 1.6.2. Gearman
    7. 1.7. The New Picture
    8. 1.8. The Future of Open-Source Web Development and Databases
    9. 1.9. Projects to Watch!
    10. 1.10. Summary
  9. 2. MySQL
    1. 2.1. How CGI and PHP Changed the Web Dramatically
    2. 2.2. About MySQL
    3. 2.3. MySQL Programs
      1. 2.3.1. Client Programs
        1. 2.3.1.1. mysql
        2. 2.3.1.2. mysql>
        3. 2.3.1.3. mysqldump
        4. 2.3.1.4. mysqladmin
        5. 2.3.1.5. mysqlimport
        6. 2.3.1.6. mysqlshow
      2. 2.3.2. Utility Programs
        1. 2.3.2.1. myisamchk
        2. 2.3.2.2. mysqlbinlog
        3. 2.3.2.3. mysql_config
      3. 2.3.3. MySQL Daemon and Startup Utilities
        1. 2.3.3.1. mysqld
        2. 2.3.3.2. mysqld_safe
        3. 2.3.3.3. mysql.server
        4. 2.3.3.4. mysqld_multi
    4. 2.4. Working with Data
      1. 2.4.1. Creating a Schema and Tables
        1. 2.4.1.1. What Exactly Is (or Is Not) NULL?
        2. 2.4.1.2. Column Data Types
        3. 2.4.1.3. Indexes
        4. 2.4.1.4. Schema Information
        5. 2.4.1.5. Schema Modification
      2. 2.4.2. Inserting Data
        1. 2.4.2.1. Basic Insert
        2. 2.4.2.2. Bulk Insert
        3. 2.4.2.3. INSERT IGNORE
        4. 2.4.2.4. Delayed and Low Priority INSERTs
      3. 2.4.3. Querying Data
        1. 2.4.3.1. Basic Queries
        2. 2.4.3.2. Aliasing
        3. 2.4.3.3. Limiting Results
        4. 2.4.3.4. WHERE Clause
        5. 2.4.3.5. Operators
        6. 2.4.3.6. Ranges
        7. 2.4.3.7. Ordering
        8. 2.4.3.8. Grouping
        9. 2.4.3.9. JOIN
        10. 2.4.3.10. UNION
        11. 2.4.3.11. INSERT . . . SELECT
      4. 2.4.4. Updating Data
      5. 2.4.5. Deleting Data
      6. 2.4.6. Replacing Data
      7. 2.4.7. INSERT ... ON DUPLICATE KEY UPDATE
      8. 2.4.8. Operators
      9. 2.4.9. Functions
        1. 2.4.9.1. Informational Functions
        2. 2.4.9.2. Aggregate Functions
        3. 2.4.9.3. Numeric Functions
        4. 2.4.9.4. String Functions
        5. 2.4.9.5. Date Functions
        6. 2.4.9.6. Date and Time Functions; Control Flow Functions
      10. 2.4.10. Using Help
      11. 2.4.11. User-Defined Variables in MySQL
    5. 2.5. MySQL Privileges
      1. 2.5.1. MySQL Access Control Privilege System
      2. 2.5.2. MySQL Global System User
      3. 2.5.3. MySQL System Schema Grant Tables
      4. 2.5.4. Account Management
        1. 2.5.4.1. CREATE USER
        2. 2.5.4.2. DROP USER
        3. 2.5.4.3. SET PASSWORD
        4. 2.5.4.4. GRANT
        5. 2.5.4.5. SHOW GRANTS
        6. 2.5.4.6. INFORMATION SCHEMA
    6. 2.6. Summary
  10. 3. Advanced MySQL
    1. 3.1. SQL Features
      1. 3.1.1. Stored Procedures and Functions
        1. 3.1.1.1. Why Would You (Not) Want to Use Stored Procedures or Functions?
        2. 3.1.1.2. Syntax
        3. 3.1.1.3. Example 1
        4. 3.1.1.4. Example 2
        5. 3.1.1.5. Example 3
        6. 3.1.1.6. Example 4
        7. 3.1.1.7. Example Summary
      2. 3.1.2. Triggers
        1. 3.1.2.1. Creating a Trigger
        2. 3.1.2.2. First Trigger Example
        3. 3.1.2.3. Second Trigger Example
        4. 3.1.2.4. Third Trigger Example
        5. 3.1.2.5. Trigger Limitations in MySQL
      3. 3.1.3. Views
      4. 3.1.4. User Defined Functions
        1. 3.1.4.1. Writing a UDF
        2. 3.1.4.2. UDF Required Functions
        3. 3.1.4.3. Simple User-Defined Function Example
    2. 3.2. Storage Engines
      1. 3.2.1. Commonly Used Storage Engines
      2. 3.2.2. Storage Engine Abilities
    3. 3.3. Using Storage Engines
      1. 3.3.1. MyISAM
        1. 3.3.1.1. Creating a MyISAM Table
        2. 3.3.1.2. MyISAM Under the Hood
        3. 3.3.1.3. MyISAM Table Maintenance
      2. 3.3.2. InnoDB
        1. 3.3.2.1. InnoDB Configuration
        2. 3.3.2.2. Creating An InnoDB Table
        3. 3.3.2.3. InnoDB Under the Hood
        4. 3.3.2.4. The Beauty of Transactions
      3. 3.3.3. Archive
        1. 3.3.3.1. Archive under the Hood
        2. 3.3.3.2. Archive Table Maintenance
      4. 3.3.4. The Federated Storage Engine
        1. 3.3.4.1. Characteristics of the Federated Storage Engine
        2. 3.3.4.2. Creating a Federated Table
        3. 3.3.4.3. Federated Servers
        4. 3.3.4.4. Federated under the Hood
      5. 3.3.5. Tina/CSV Storage Engine
        1. 3.3.5.1. Creating a CSV Table
        2. 3.3.5.2. CSV under the Hood
      6. 3.3.6. Blackhole Storage Engine
    4. 3.4. Replication
      1. 3.4.1. Replication Overview
      2. 3.4.2. Replication schemes
      3. 3.4.3. Replication Command Options
      4. 3.4.4. Setting Up Replication
        1. 3.4.4.1. Running Multiple Instances of MySQL with mysqld_multi
        2. 3.4.4.2. Adding Replication Command Options
        3. 3.4.4.3. Verify the Replication is Running
        4. 3.4.4.4. Manually Setting the Master
      5. 3.4.5. Searching Text
        1. 3.4.5.1. MySQL FULLTEXT Indexes
        2. 3.4.5.2. Using MySQL Full-text Indexes
        3. 3.4.5.3. Full-text Index Issues
        4. 3.4.5.4. Sphinx Full-Text Search Engine
        5. 3.4.5.5. Sphinx Configuration and Installation
        6. 3.4.5.6. Sphinx.conf Settings
          1. 3.4.5.6.1. Sphinx Data Sources
          2. 3.4.5.6.2. Sphinx Indexes
          3. 3.4.5.6.3. Sphinx Indexer Section
          4. 3.4.5.6.4. The searchd Section
          5. 3.4.5.6.5. Defining the Main Index
        7. 3.4.5.7. Starting Sphinx
        8. 3.4.5.8. Searching Sphinx
          1. 3.4.5.8.1. Boolean Query Syntax
          2. 3.4.5.8.2. The Utility Search
      6. 3.4.6. When to Use Sphinx
    5. 3.5. Summary
  11. 4. Perl Primer
    1. 4.1. What Exactly Is Perl?
    2. 4.2. Perl Primer
    3. 4.3. Perl Data Types
      1. 4.3.1. Scalars
      2. 4.3.2. Arrays
      3. 4.3.3. Hashes
      4. 4.3.4. File Handles
      5. 4.3.5. Type Globs
      6. 4.3.6. Subroutines
    4. 4.4. Variable Usage
      1. 4.4.1. References
        1. 4.4.1.1. Scalar References
        2. 4.4.1.2. Array References
        3. 4.4.1.3. Hash References
        4. 4.4.1.4. Reducing Arguments Passed with Hash References
        5. 4.4.1.5. Subroutine References
        6. 4.4.1.6. Using a Hash to Create a Dispatch Table
        7. 4.4.1.7. Identifying References
      2. 4.4.2. Scalar Usage
      3. 4.4.3. Array Usage and Iteration
        1. 4.4.3.1. for/foreach loop:
        2. 4.4.3.2. map
        3. 4.4.3.3. Adding and Splicing Arrays
        4. 4.4.3.4. shift, unshift, pop, and push
        5. 4.4.3.5. split and join
        6. 4.4.3.6. sort
        7. 4.4.3.7. reverse
        8. 4.4.3.8. scalar
        9. 4.4.3.9. Last Subscript Value of Array
        10. 4.4.3.10. Array Slices
        11. 4.4.3.11. Printing an Array
      4. 4.4.4. Working with Hashes
        1. 4.4.4.1. Looping: keys and values
        2. 4.4.4.2. Make a Hash Out of Two Arrays
        3. 4.4.4.3. Hashes as Arrays
        4. 4.4.4.4. Complex Perl Data Structures
        5. 4.4.4.5. File Handles
        6. 4.4.4.6. File Functions
        7. 4.4.4.7. Reading Files
      5. 4.4.5. Writing to Files
      6. 4.4.6. STDOUT and STDERR
      7. 4.4.7. File Handles to Processes
        1. 4.4.7.1. Reading from Process File Handles
        2. 4.4.7.2. Writing to Process File Handles
        3. 4.4.7.3. Directory Handles
      8. 4.4.8. Subroutines
        1. 4.4.8.1. shift Versus Using @_
        2. 4.4.8.2. Who Called?
      9. 4.4.9. Variable Scope
        1. 4.4.9.1. Symbol Table
        2. 4.4.9.2. Scope Example
        3. 4.4.9.3. Forcing Scope Adherence
    5. 4.5. Packages
      1. 4.5.1. Perl Modules
      2. 4.5.2. Writing a Perl Module
      3. 4.5.3. @ISA array
      4. 4.5.4. Documenting Your Module
      5. 4.5.5. Making Your Module Installable
      6. 4.5.6. Testing
      7. 4.5.7. Adding a MANIFEST file
      8. 4.5.8. CPAN
    6. 4.6. Regex One-Liners
      1. 4.6.1. Storing Regular Expressions in Variables
      2. 4.6.2. Regex Optimizations
        1. 4.6.2.1. Regex Compilation
        2. 4.6.2.2. Grouping Optimization
    7. 4.7. Perl 6 Tidbits
    8. 4.8. Summary
  12. 5. Object-Oriented Perl
    1. 5.1. About Object Orientation
    2. 5.2. Object Orientation in Perl
      1. 5.2.1. Writing a Perl Class
        1. 5.2.1.1. Creating a Package
        2. 5.2.1.2. Constructors
      2. 5.2.2. Adding Methods
        1. 5.2.2.1. Accessors
        2. 5.2.2.2. Setting Methods
      3. 5.2.3. On-Demand Method Manifestation Using AUTOLOAD
      4. 5.2.4. Other Methods
        1. 5.2.4.1. Debug
        2. 5.2.4.2. Documentation
        3. 5.2.4.3. Inheritance and Felidea Subclassing
      5. 5.2.5. Making Life Easier: Moose
    3. 5.3. Summary
  13. 6. MySQL and Perl
    1. 6.1. Perl DBI
      1. 6.1.1. DBI and DBD
      2. 6.1.2. Installation
        1. 6.1.2.1. Ubuntu
        2. 6.1.2.2. Redhat, CentOS
        3. 6.1.2.3. CPAN
      3. 6.1.3. DBI API
        1. 6.1.3.1. Loading DBI
        2. 6.1.3.2. Driver Methods
    2. 6.2. Connect
      1. 6.2.1. $dsn
      2. 6.2.2. $username and $password
      3. 6.2.3. $attributes
      4. 6.2.4. connect_cached
    3. 6.3. Statement Handles
      1. 6.3.1. Writing Data
      2. 6.3.2. Reading Data
      3. 6.3.3. Fetch Methods, One Row at a Time
      4. 6.3.4. Fetch Methods—the Whole Shebang
        1. 6.3.4.1. fetchall_arrayref
        2. 6.3.4.2. fetchall_hashref
        3. 6.3.4.3. Finish
    4. 6.4. Binding Methods
      1. 6.4.1. Binding Input Parameters
      2. 6.4.2. Binding Output Parameters
    5. 6.5. Other Statement Handle Methods
      1. 6.5.1. rows
      2. 6.5.2. dump_results
    6. 6.6. Statement Handle Attributes
    7. 6.7. MySQL-Specific Statement Handle Attributes
    8. 6.8. Multistep Utility Methods
      1. 6.8.1. do
      2. 6.8.2. selectall_arrayref
      3. 6.8.3. selectall_hashref
      4. 6.8.4. selectcol_arrayref
      5. 6.8.5. selectrow_array
      6. 6.8.6. selectrow_arrayref
      7. 6.8.7. selectrow_hashref
    9. 6.9. Other Database Handle Methods
      1. 6.9.1. last_insert_id
      2. 6.9.2. ping
      3. 6.9.3. clone
      4. 6.9.4. Transactional Methods—begin_work, commit, rollback
    10. 6.10. Stored Procedures
    11. 6.11. Error Handling
    12. 6.12. Server Admin
    13. 6.13. Summary
  14. 7. Simple Database Application
    1. 7.1. Planning Application Functionality
      1. 7.1.1. Schema Design
      2. 7.1.2. Writing Up a Wire-Frame
      3. 7.1.3. Declarations, Initializations
      4. 7.1.4. Program Entry Point
    2. 7.2. Table Creation Subroutine
      1. 7.2.1. Using information_schema
      2. 7.2.2. Listing Contacts
      3. 7.2.3. Editing a Contact
      4. 7.2.4. Inserting a Contact
      5. 7.2.5. Updating a Contact
      6. 7.2.6. Deleting a Contact
    3. 7.3. Testing update_contact, insert_contact, and delete_contact
      1. 7.3.1. Editing a Contact
      2. 7.3.2. Adding a Contact
      3. 7.3.3. Deleting a Contact
    4. 7.4. Lookup of a Contact
    5. 7.5. Testing Lookup of a Contact
    6. 7.6. Summary
  15. 8. memcached
    1. 8.1. What Is memcached?
    2. 8.2. How memcached Is Used
      1. 8.2.1. What Is Gearman?
      2. 8.2.2. Caching Strategies
    3. 8.3. Installing memcached
      1. 8.3.1.
        1. 8.3.1.1. CentOS
        2. 8.3.1.2. Ubuntu
        3. 8.3.1.3. Installing memcached from Source
    4. 8.4. Starting memcached
      1. 8.4.1. Startup Scripts
        1. 8.4.1.1. Debian-Based Startup Scripts
        2. 8.4.1.2. Redhat-based Startup Scripts
      2. 8.4.2. Installing the Cache::Memcached Perl Module
    5. 8.5. Using Cache::Memcached
      1. 8.5.1. Connecting, Instantiation
      2. 8.5.2. Memcached Operations
      3. 8.5.3. Cache::Memcached API
    6. 8.6. Simple Examples
      1. 8.6.1. Storing a Scalar
      2. 8.6.2. Complex Data Types
      3. 8.6.3. Add and Replace
    7. 8.7. A More Practical Example
      1. 8.7.1. User Application
      2. 8.7.2. Data Design
      3. 8.7.3. UserApp Package
      4. 8.7.4. Instantiation
      5. 8.7.5. Database Connector Method
      6. 8.7.6. Data Retrieval Methods
      7. 8.7.7. Simple Accessor Methods
      8. 8.7.8. Data Modification Methods
      9. 8.7.9. Using UserApp
      10. 8.7.10. Memcached Connector Method
      11. 8.7.11. Caching Implementation Plan
      12. 8.7.12. Where to Add Caching?
      13. 8.7.13. Caching Key Scheme
      14. 8.7.14. Precaching
      15. 8.7.15. Precaching Cities
      16. 8.7.16. Precaching States
      17. 8.7.17. Using Instantiation for Precaching Method Calls
      18. 8.7.18. Modifying Accessor Methods to Use Cache
        1. 8.7.18.1. getCity()
        2. 8.7.18.2. getState()
        3. 8.7.18.3. No Change Needed for Accessor Methods
      19. 8.7.19. User Data Caching—Set Method Modifications
      20. 8.7.20. User Data Caching—Get Method Modifications
      21. 8.7.21. UserApp Now Has Caching!
      22. 8.7.22. Other Caching Issues
        1. 8.7.22.1. Cache Stampede/Dog-Piling/Thundering Herd
        2. 8.7.22.2. Example of a Stale Key Used to Avoid Dog-Pile Effect
        3. 8.7.22.3. Replicating Data to Multiple Caches
    8. 8.8. Summary
  16. 9. Libmemcached
    1. 9.1. What Is libmemcached?
      1. 9.1.1. libmemcached Features
      2. 9.1.2. Libmemcache Utility Programs
      3. 9.1.3. Installing libmemcached
    2. 9.2. libmemcached Utility Programs
      1. 9.2.1. memcat
      2. 9.2.2. memflush
      3. 9.2.3. memcp
      4. 9.2.4. memstat
      5. 9.2.5. memrm
      6. 9.2.6. memslap
      7. 9.2.7. memerror
    3. 9.3. libmemcached Perl Driver
      1. 9.3.1. Installation
      2. 9.3.2. Memcached::libmemcached and libmemcached API using Memcached::libmemcached
      3. 9.3.3. Connection Functions
      4. 9.3.4. libmemcached Behavioral Functions
      5. 9.3.5. Functions for Setting Values
      6. 9.3.6. Data Retrieval (get) Functions
      7. 9.3.7. Increment, Decrement, and Delete
      8. 9.3.8. Informational and Utility Functions
      9. 9.3.9. Object-Oriented Interface
      10. 9.3.10. Procedure Memcached::libmemcached Program Example
      11. 9.3.11. Object-Oriented Memcached::libmemcached Program Example
    4. 9.4. Cache::memcached::libmemcached
      1. 9.4.1. Performance Comparisons
      2. 9.4.2. Writing Your Own Comparison Script
    5. 9.5. Summary
  17. 10. Memcached Functions for MySQL
    1. 10.1. What Are Memcached Functions for MySQL?
    2. 10.2. How Do the Memcached Functions for MySQL Work?
    3. 10.3. Install the Memcached Functions for MySQL
      1. 10.3.1. Prerequisites
      2. 10.3.2. Configure the Source
      3. 10.3.3. Build the Source
      4. 10.3.4. Install the UDF
        1. 10.3.4.1. SQL Script Install
        2. 10.3.4.2. Perl Install Utility
      5. 10.3.5. Checking Installation
    4. 10.4. Using the Memcached Functions for MySQL
      1. 10.4.1. Establishing a Connection to the memcached Server
        1. 10.4.1.1. memc_servers_set
        2. 10.4.1.2. memc_server_count
      2. 10.4.2. Setting Values
        1. 10.4.2.1. memc_set
        2. 10.4.2.2. memc_set_by_key
        3. 10.4.2.3. memc_add
        4. 10.4.2.4. memc_replace
        5. 10.4.2.5. memc_cas
        6. 10.4.2.6. memc_prepend
        7. 10.4.2.7. memc_append
        8. 10.4.2.8. memc_delete
      3. 10.4.3. Fetching, Incrementing, and Decrementing Functions
        1. 10.4.3.1. memc_get
        2. 10.4.3.2. memc_increment
        3. 10.4.3.3. memc_decrement
      4. 10.4.4. Behavioral Functions
        1. 10.4.4.1. memc_list_behaviors
        2. 10.4.4.2. memc_behavior_get
        3. 10.4.4.3. memc_behavior_set
        4. 10.4.4.4. memc_list_hash_types
        5. 10.4.4.5. memc_list_distribution_types
      5. 10.4.5. Statistical Functions
        1. 10.4.5.1. memc_stats
        2. 10.4.5.2. memc_stat_get_value
        3. 10.4.5.3. memc_stat_get_keys
      6. 10.4.6. Version Functions
        1. 10.4.6.1. memc_libmemcached_version
        2. 10.4.6.2. memc_udf_version
    5. 10.5. Using memcached UDFs
      1. 10.5.1. Single Database Handle Example
        1. 10.5.1.1. Changes to Connection
        2. 10.5.1.2. Changes to getUser()
        3. 10.5.1.3. Creating More Convenience with Generic Get and Set Methods
      2. 10.5.2. Fun with Triggers (and UDFs)
      3. 10.5.3. Read-Through Caching with Simple Select Statements
      4. 10.5.4. Updates, Too!
    6. 10.6. Summary
  18. 11. Apache
    1. 11.1. Understanding Apache: An Overview
    2. 11.2. Understanding the Apache Modules API
      1. 11.2.1. Apache 2.2 Changes Since Apache 1.3
      2. 11.2.2. Apache 2.2 Request Phases
        1. 11.2.2.1. Request Parsing Phase
        2. 11.2.2.2. Security Phase
        3. 11.2.2.3. Preparation Phase
        4. 11.2.2.4. Handler Phase
        5. 11.2.2.5. Understanding Hooks and Filters
      3. 11.2.3. New and Modified Modules
    3. 11.3. Installing Apache
      1. 11.3.1. Installing Apache on Windows
        1. 11.3.1.1. Installation of mod_perl
      2. 11.3.2. Installing Apache and mod_perl on a Working UNIX System
        1. 11.3.2.1. Ubuntu/Debian-based Linux
        2. 11.3.2.2. Redhat-Based Systems (Centos, Fedora, Redhat Enterprise, etc.)
      3. 11.3.3. Installing Apache on Apple OS X (10.5)
      4. 11.3.4. Apache Source Install on UNIX
    4. 11.4. Installing mod_perl from Source
    5. 11.5. Installing libapreq2 from Source
    6. 11.6. Apache Configuration
      1. 11.6.1. Configuration Section Container Directives
        1. 11.6.1.1. <Directory> and <DirectoryMatch>
        2. 11.6.1.2. <Files> and <FilesMatch>
        3. 11.6.1.3. <Location>
        4. 11.6.1.4. <LocationMatch>
        5. 11.6.1.5. <IfDefine>
        6. 11.6.1.6. <IfModule>
        7. 11.6.1.7. <IfVersion>
        8. 11.6.1.8. <Limit>
        9. 11.6.1.9. <LimitExcept>
        10. 11.6.1.10. <Proxy>
        11. 11.6.1.11. <ProxyMatch>
        12. 11.6.1.12. <VirtualHost>
      2. 11.6.2. Basic Directives
        1. 11.6.2.1. ServerName
        2. 11.6.2.2. ServerRoot
        3. 11.6.2.3. DocumentRoot
        4. 11.6.2.4. Include
        5. 11.6.2.5. Listen
        6. 11.6.2.6. LoadModule
        7. 11.6.2.7. Options
        8. 11.6.2.8. Redirect
        9. 11.6.2.9. User
        10. 11.6.2.10. AddType
      3. 11.6.3. Server Tuning Directives
        1. 11.6.3.1. StartServers
        2. 11.6.3.2. MaxClients
        3. 11.6.3.3. MaxSpareServers
        4. 11.6.3.4. MinSpareServers
        5. 11.6.3.5. ServerLimit
        6. 11.6.3.6. MaxRequestsPerChild
        7. 11.6.3.7. ThreadLimit
        8. 11.6.3.8. ThreadsPerChild
        9. 11.6.3.9. KeepAlive
        10. 11.6.3.10. MaxKeepAliveRequests
        11. 11.6.3.11. KeepAliveTimeout
        12. 11.6.3.12. Timeout
      4. 11.6.4. Logging Directives
        1. 11.6.4.1. CustomLog
        2. 11.6.4.2. TransferLog
        3. 11.6.4.3. ErrorLog
        4. 11.6.4.4. LogFormat
        5. 11.6.4.5. LogLevel
      5. 11.6.5. Error Directives
        1. 11.6.5.1. ErrorDocument
        2. 11.6.5.2. ServerSignature
      6. 11.6.6. Access Control, Authentication, and Authorization
        1. 11.6.6.1. Access Control
        2. 11.6.6.2. Authentication
        3. 11.6.6.3. Authorization
        4. 11.6.6.4. Order
        5. 11.6.6.5. Require
        6. 11.6.6.6. AuthName
        7. 11.6.6.7. AuthType
        8. 11.6.6.8. AuthBasicProvider
        9. 11.6.6.9. AuthUserFile
        10. 11.6.6.10. AuthGroupFile
        11. 11.6.6.11. AuthDBMType
        12. 11.6.6.12. AuthDBMUserFile
      7. 11.6.7. .htaccess File Directives
        1. 11.6.7.1. AccessFileName
        2. 11.6.7.2. AllowOverride
      8. 11.6.8. Indexing Directives
        1. 11.6.8.1. DirectoryIndex
        2. 11.6.8.2. HeaderName
        3. 11.6.8.3. IndexOptions
        4. 11.6.8.4. IndexOrderDefault
        5. 11.6.8.5. HeaderName
        6. 11.6.8.6. AddIcon
        7. 11.6.8.7. AddIconByEncoding
        8. 11.6.8.8. AddIconByType
        9. 11.6.8.9. DefaultIcon
        10. 11.6.8.10. IndexIgnore
      9. 11.6.9. CGI Directives
        1. 11.6.9.1. ScriptAlias
        2. 11.6.9.2. ScriptAliasMatch
        3. 11.6.9.3. User Directory Directives
        4. 11.6.9.4. UserDir
      10. 11.6.10. VirtualHost Directives
        1. 11.6.10.1. Types of Virtual Hosting
        2. 11.6.10.2. NameVirtualHost
      11. 11.6.11. Handler and Filter Directives
        1. 11.6.11.1. AddHandler
        2. 11.6.11.2. SetHandler
        3. 11.6.11.3. AddInputFilter
        4. 11.6.11.4. AddOutputFilter
      12. 11.6.12. Client Handling
        1. 11.6.12.1. BrowserMatch
      13. 11.6.13. SSL Directives
        1. 11.6.13.1. SSLEngine
        2. 11.6.13.2. SSLRequireSSL
        3. 11.6.13.3. SSLCertificateFile
        4. 11.6.13.4. SSLCertificateKeyFile
        5. 11.6.13.5. SSLSessionCache
        6. 11.6.13.6. SLSessionCacheTimeout
        7. 11.6.13.7. SSLMutex
        8. 11.6.13.8. Limitations when Using Virtual Hosts and SSL
      14. 11.6.14. Clickstream Analysis
      15. 11.6.15. Rewriting URLs
        1. 11.6.15.1. RewriteEngine
        2. 11.6.15.2. RewriteCond
        3. 11.6.15.3. Test String
        4. 11.6.15.4. Back-References
        5. 11.6.15.5. Rewrite Map Extensions
      16. 11.6.16. Conditional Pattern
        1. 11.6.16.1. Flags
        2. 11.6.16.2. RewriteRule
        3. 11.6.16.3. Condition-Pattern
        4. 11.6.16.4. Substitution
        5. 11.6.16.5. Flags
        6. 11.6.16.6. RewriteLog
        7. 11.6.16.7. RewriteLogLevel
      17. 11.6.17. Apache Reverse Proxying
      18. 11.6.18. Enabling mod_proxy
      19. 11.6.19. mod_proxy Directives
        1. 11.6.19.1. ProxyPass
        2. 11.6.19.2. ProxyPassReverse
        3. 11.6.19.3. ProxyPassReverseCookieDomain
        4. 11.6.19.4. ProxyPassReverseCookiePath
        5. 11.6.19.5. ProxyPreserveHost
      20. 11.6.20. Apache Server Control
    7. 11.7. Apache Configuration Schemes
      1. 11.7.1. Source Install
      2. 11.7.2. Ubuntu/Debian
        1. 11.7.2.1. Configuration Files
        2. 11.7.2.2. Documents, Content
        3. 11.7.2.3. Apache Modules
        4. 11.7.2.4. Binary Files
        5. 11.7.2.5. Apache Server Control
      3. 11.7.3. Centos/Redhat Variants
        1. 11.7.3.1. Configuration Files
        2. 11.7.3.2. Binary Files, Server Control
        3. 11.7.3.3. Documents, Content
      4. 11.7.4. SUSE
        1. 11.7.4.1. Configuration Files
        2. 11.7.4.2. Binaries
        3. 11.7.4.3. Modules
        4. 11.7.4.4. Documents, Content
        5. 11.7.4.5. Apache Server Control
      5. 11.7.5. Windows
        1. 11.7.5.1. Configuration
        2. 11.7.5.2. Configuration Files
        3. 11.7.5.3. Other Files
        4. 11.7.5.4. Apache Administration on Windows
    8. 11.8. Common Apache Tasks
      1. 11.8.1. Configuring a Name-Based Virtual Host
        1. 11.8.1.1. Step 1: Modify Your Apache Configuration File
        2. 11.8.1.2. Step 2: Create the Virtual Host Directories
        3. 11.8.1.3. Step 3: Restart Apache
        4. 11.8.1.4. Adding Other Virtual Hosts
      2. 11.8.2. Setting Up HTTP Basic Authentication
        1. 11.8.2.1. Step 1: Modify the Apache Configuration
        2. 11.8.2.2. Step 2: Adding Users to the Password File
        3. 11.8.2.3. Step 3: Restart Apache
      3. 11.8.3. Setting Up Digest Authentication
        1. 11.8.3.1. Step 1: Modify Your Apache configuration
        2. 11.8.3.2. Step 2: Create Digest Users
        3. 11.8.3.3. Step 3: Restart Apache
      4. 11.8.4. Configuring a Secure Server
        1. 11.8.4.1. Step 1: Create a Self-Signed Certificate
        2. 11.8.4.2. Step 2: Add the Secure Virtual Host
        3. 11.8.4.3. Step 3: Restart Apache
      5. 11.8.5. Settin Up a Secure Server with a Valid Secure Certificate
        1. 11.8.5.1. Step 1: Create a Key and Certificate Request
        2. 11.8.5.2. Step 2: Obtain a Certificate Using the Certificate Request
        3. 11.8.5.3. Step 3: Set Up a Virtual Host
        4. 11.8.5.4. Step 4: Restart Apache
      6. 11.8.6. Setting up a Reverse Proxy with Two Virtual Hosts
        1. 11.8.6.1. Step 1: Set Up the Internal Virtual Host
        2. 11.8.6.2. Step 2: Add Proxy Directives to the Front-End Server Configuration
        3. 11.8.6.3. Step 3: Restart Apache
    9. 11.9. Summary
  19. 12. Contact List Application
    1. 12.1. Using MySQL and memcached Together
    2. 12.2. A CGI Program
      1. 12.2.1. CGI Apache Setup
      2. 12.2.2. Your Basic CGI Program, and Then Some
        1. 12.2.2.1. Understanding the Application's Functionality
        2. 12.2.2.2. Conceptualizing
        3. 12.2.2.3. Program Requirements
      3. 12.2.3. User Interface
        1. 12.2.3.1. The Main User Form, User Listing
        2. 12.2.3.2. User Edit Form
        3. 12.2.3.3. Contact View Page
      4. 12.2.4. Database Storage Requirements
    3. 12.3. Program Flow
      1. 12.3.1. First Things First
      2. 12.3.2. Program Implementation
        1. 12.3.2.1. Getting Started
        2. 12.3.2.2. main() Subroutine
        3. 12.3.2.3. header() Subroutine
        4. 12.3.2.4. dispatcher() Subroutine
        5. 12.3.2.5. mainform() Subroutine
        6. 12.3.2.6. userlist() Subroutine
        7. 12.3.2.7. userform() Subroutine
        8. 12.3.2.8. viewuser() Subroutine
    4. 12.4. WebApp Class Methods
      1. 12.4.1. Instantiation with the new() Method
      2. 12.4.2. Connection to MySQL
      3. 12.4.3. Connection to memcached
      4. 12.4.4. The getUsers() Method
      5. 12.4.5. The getUser() Method
      6. 12.4.6. The saveUser() Method
    5. 12.5. Database Methods
      1. 12.5.1. The insertUser() Method
      2. 12.5.2. The updateUser() Method
      3. 12.5.3. The deleteUsers() Method
      4. 12.5.4. The userExists() Method
    6. 12.6. Caching Methods
      1. 12.6.1. The saveUserToCache() Method
      2. 12.6.2. The cacheUsers() Method
      3. 12.6.3. The getUsersFromCache() Method
      4. 12.6.4. The userExistsInCache() Method
      5. 12.6.5. The deleteUserFromCache Method
      6. 12.6.6. The setMemcUIDList() Method
      7. 12.6.7. The updateMemcUIDList Method
      8. 12.6.8. The deleteMemcUIDList() Method
      9. 12.6.9. The getMemcUIDList Method
    7. 12.7. Other Methods
      1. 12.7.1. The getStates() Method
      2. 12.7.2. The getState() Method
      3. 12.7.3. The encodeUserData() Method
    8. 12.8. Testing
    9. 12.9. Summary
  20. 13. mod_perl
    1. 13.1. New mod_perl 2.0 Features
    2. 13.2. Configuring mod_perl
    3. 13.3. mod_perl Configuration Directives
      1. 13.3.1. <Perl> Sections
      2. 13.3.2. PerlModule
      3. 13.3.3. PerlLoadModule
      4. 13.3.4. SetHandler perl-script
      5. 13.3.5. SetHandler modperl
      6. 13.3.6. PerlSetEnv
      7. 13.3.7. PerlPassEnv
      8. 13.3.8. PerlSetVar
      9. 13.3.9. PerlAddVar
      10. 13.3.10. PerlPostConfigRequire
      11. 13.3.11. PerlRequire
      12. 13.3.12. PerlOptions
      13. 13.3.13. PerlSwitches
      14. 13.3.14. POD
    4. 13.4. mod_perl Handler Directives
      1. 13.4.1. Handler Scope
      2. 13.4.2. Handler Type
      3. 13.4.3. Handler Category
    5. 13.5. Apache Life Cycle Overview
      1. 13.5.1. Server Life Cycle Phase Handlers
      2. 13.5.2. Connection Cycle Phase Handlers
        1. 13.5.2.1. Connection Cycle Phase Handler Template
        2. 13.5.2.2. Connection Cycle Phase Handler Names
      3. 13.5.3. Filter Handlers
        1. 13.5.3.1. Filter Handler Template
        2. 13.5.3.2. Filter Handler Type Descriptions
        3. 13.5.3.3. HTTP Request Cycle Phase Handlers
        4. 13.5.3.4. HTTP Request Cycle Handler Template
        5. 13.5.3.5. HTTP Request Cycle Handler Phase Names
    6. 13.6. Perl Apache2 Modules
      1. 13.6.1. Apache2 Constants and Request Record Perl Modules
        1. 13.6.1.1. Apache2::Const
        2. 13.6.1.2. Apache2::Request
        3. 13.6.1.3. Apache2::RequestRec
        4. 13.6.1.4. Apache2::RequestUtil
        5. 13.6.1.5. Apache2::RequestIO
        6. 13.6.1.6. Apache2::Response
        7. 13.6.1.7. Apache2::Access
        8. 13.6.1.8. Apache2::URI
        9. 13.6.1.9. Apache2::Util
      2. 13.6.2. Apache2 Connection and Filter Record Modules
        1. 13.6.2.1. Apache2::Connection
        2. 13.6.2.2. Apache2::Filter
      3. 13.6.3. Apache2 Server Record Modules
        1. 13.6.3.1. Apache2::ServerRec
        2. 13.6.3.2. Apache2::ServerUtil
        3. 13.6.3.3. Apache2::Log
      4. 13.6.4. Apache2 Configuration Modules
        1. 13.6.4.1. Apache2::Directive
        2. 13.6.4.2. Apache2::MPM
        3. 13.6.4.3. Apache2::PerlSections
      5. 13.6.5. Apache2 Resource/Performance, Status, and Other Modules
        1. 13.6.5.1. Apache2::Reload
        2. 13.6.5.2. Apache::DBI
        3. 13.6.5.3. Apache2::Resource
        4. 13.6.5.4. Apache2::SizeLimit
        5. 13.6.5.5. Apache2::Status
    7. 13.7. Summary
  21. 14. Using mod_perl Handlers
    1. 14.1. PerlResponseHandler Example
      1. 14.1.1. Initial Handler Setup
      2. 14.1.2. Log Messages Using the Server Object and Form Parsing
      3. 14.1.3. Setting the Log Level and Printing the HTTP Header
      4. 14.1.4. Redirection
      5. 14.1.5. Print the Document Header
    2. 14.2. Connection mod_perl Handlers
    3. 14.3. PerlPreConnectionHandler Example
    4. 14.4. Other HTTP Request Cycle Phase Handlers
      1. 14.4.1. PerlAccessHandler Example
      2. 14.4.2. PerlAuthenHandler Example
      3. 14.4.3. PerlAuthzHandler Example
      4. 14.4.4. PerlLogHandler Example
      5. 14.4.5. Perl Filter Handler Example
    5. 14.5. Summary
  22. 15. More mod_perl
    1. 15.1. mod_perl Handlers or ModPerl::Registry?
      1. 15.1.1. Using ModPerl::RegistryLoader
      2. 15.1.2. Converting a ModPerl::Registry Script to a mod_perl Handler
      3. 15.1.3. Converting a mod_perl Handler to a ModPerl::Registry Script
    2. 15.2. Dealing with Cookies
      1. 15.2.1. CookieTestHandler
      2. 15.2.2. Tools for Testing Cookies and Headers
    3. 15.3. Generic Database Methods
      1. 15.3.1. dbGetRef()
      2. 15.3.2. dbInsert()
      3. 15.3.3. dbUpdate()
      4. 15.3.4. dbDelete()
      5. 15.3.5. whereClause()
      6. 15.3.6. buildUpdate()
      7. 15.3.7. buildInsert ()
      8. 15.3.8. Other Changes to WebApp
    4. 15.4. Session Management
      1. 15.4.1. Implementing the mod_perl Handler LoginHandler
      2. 15.4.2. Understanding the WebApp Class
      3. 15.4.3. Storing Session Data
    5. 15.5. File Upload mod_perl Handler
      1. 15.5.1. Storing Files in the Database or Not?
      2. 15.5.2. Database Table
      3. 15.5.3. mod_perl Handler Implementation
        1. 15.5.3.1. Set Up the Uploads Directory in the Apache Configuration
        2. 15.5.3.2. Implement the mod_perl Handler
        3. 15.5.3.3. The handler() Subroutine
        4. 15.5.3.4. The saveUpload() Subroutine
      4. 15.5.4. Methods That Need to be Added to WebApp
        1. 15.5.4.1. getFiles() Method
        2. 15.5.4.2. fileExists() Method
        3. 15.5.4.3. saveFileInfo() Method
      5. 15.5.5. Using the mod_perl Upload Handler
    6. 15.6. Templating
      1. 15.6.1. Template Toolkit
      2. 15.6.2. Features
      3. 15.6.3. Plug-Ins to Template Toolkit
      4. 15.6.4. Template Toolkit Syntax
      5. 15.6.5. A mod_perl Handler Example Using Template Toolkit
        1. 15.6.5.1. Handler Declaration in the Apache Configuration File
        2. 15.6.5.2. Handler Body
      6. 15.6.6. Caching Templates
    7. 15.7. HTML::Template
      1. 15.7.1. Tags
      2. 15.7.2. A mod_perl Handler Example Using HTML::Template
      3. 15.7.3. HTML::Template template
    8. 15.8. HTML::Mason (Mason)
      1. 15.8.1. Mason Syntax
      2. 15.8.2. In-Line Perl Sections
      3. 15.8.3. Mason Objects
      4. 15.8.4. Mason Components
      5. 15.8.5. Initialization and Cleanup
      6. 15.8.6. Userlisting Page in Mason
    9. 15.9. Summary
  23. 16. Perl and Ajax
    1. 16.1. What Is Ajax?
    2. 16.2. mod_perl Applications and Ajax
      1. 16.2.1. Basic Ajax Examples
        1. 16.2.1.1. Example 1
        2. 16.2.1.2. mod_perl Handler for Example 1
        3. 16.2.1.3. Ajax Example 2: Display Returned HTML Table
        4. 16.2.1.4. mod_perl Handler for Example 2
        5. 16.2.1.5. Example 2: Template Code
      2. 16.2.2. More Examples Using the JSON Perl Module
        1. 16.2.2.1. Ajax Example 3: Building the Table on the Client
        2. 16.2.2.2. Example 3: mod_perl Handler
        3. 16.2.2.3. Example 4: MySQL Ajax Client
        4. 16.2.2.4. Example 4: mod_perl Handler
        5. 16.2.2.5. Example 4 in Action
        6. 16.2.2.6. Example 5: Reading the Raw Post Data
        7. 16.2.2.7. Example 5: mod_perl Handler
        8. 16.2.2.8. Example 6: Using the Prototype JavaScript Framework
        9. 16.2.2.9. Example 7: Account Creation with Ajax
        10. 16.2.2.10. Account Page mod_perl Handler
        11. 16.2.2.11. Account Page Template
        12. 16.2.2.12. Account Handler
          1. 16.2.2.12.1. The handler() Subroutine
          2. 16.2.2.12.2. The notifyUser() Subroutine
        13. 16.2.2.13. New WebApp Method sendEmail()
        14. 16.2.2.14. Ajax Account Creation in Action
    3. 16.3. Summary
  24. 17. Search Engine Application
    1. 17.1. Using Gearman to Put the Search Engine Application Together
      1. 17.1.1.
        1. 17.1.1.1. Gearman
      2. 17.1.2. Installing and Running Gearman
        1. 17.1.2.1. gearmand Job Server Install
        2. 17.1.2.2. Gearman MySQL UDF Install
        3. 17.1.2.3. Running the Gearman Job Server
      3. 17.1.3. Using the Gearman MySQL UDFs
        1. 17.1.3.1. gman_severs_set()
        2. 17.1.3.2. gman_do()
        3. 17.1.3.3. gman_sum()
        4. 17.1.3.4. Usage Examples
      4. 17.1.4. Perl and Gearman
        1. 17.1.4.1. Perl Gearman Worker
        2. 17.1.4.2. Perl Gearman Client
    2. 17.2. The Search Engine Application
      1. 17.2.1. Database Tables for the Search Engine Application
      2. 17.2.2. Database Triggers
      3. 17.2.3. Sphinx Setup
      4. 17.2.4. Gearman Workers
        1. 17.2.4.1. Web Client Worker
        2. 17.2.4.2. Data Storage Worker
        3. 17.2.4.3. Indexer Worker
      5. 17.2.5. Running the Workers
    3. 17.3. mod_perl Handler Web Applications
      1. 17.3.1. Search Application
        1. 17.3.1.1. Search Template
        2. 17.3.1.2. The mod_perl Search Handler
        3. 17.3.1.3. Main Handler Method
        4. 17.3.1.4. The search() Subroutine
        5. 17.3.1.5. The get_results_from_db() Subroutine
        6. 17.3.1.6. Paginating the Search Application
      2. 17.3.2. Using the Search Application
      3. 17.3.3. URL Queue Application
      4. 17.3.4. URLHandler—AJAX Application
        1. 17.3.4.1. The Main handler() Subroutine
        2. 17.3.4.2. URLHandler JavaScript
        3. 17.3.4.3. JavaScript Functions
        4. 17.3.4.4. URLHandler Template
      5. 17.3.5. URLQueueHandler mod_perl Handler
    4. 17.4. URLQueueHandler handler() Subroutine
      1. 17.4.1. URLQueue Interface
    5. 17.5. Summary
  25. A. Installing MySQL
    1. A.1. Choosing a MySQL Version
    2. A.2. Choosing a MySQL Package Type
    3. A.3. Installing MySQL on Windows
    4. A.4. Installing MySQL on RPM-based Linux Systems
    5. A.5. Installing MySQL on Ubuntu
    6. A.6. Installing MySQL from Source on UNIX Systems
    7. A.7. Unix Post Install
  26. B. Configuring MySQL
    1. B.1. Running MySQL for the First Time
    2. B.2. Setting Up Privileges and Creating a Schema
    3. B.3. MySQL Server Configuration File
      1. B.3.1. Basic Command Options
        1. B.3.1.1. datadir
        2. B.3.1.2. tmpdir
        3. B.3.1.3. user
        4. B.3.1.4. port
        5. B.3.1.5. socket
      2. B.3.2. InnoDB Path and Tablespace Command Options
        1. B.3.2.1. innodb_data_file_path
        2. B.3.2.2. innodb_file_per_table
    4. B.4. Backups
      1. B.4.1. Replication Backup Slave
      2. B.4.2. mysqldump
      3. B.4.3. Scripting mysqldump Backups with Perl
      4. B.4.4. Creating a Backup by Copying Data Files
      5. B.4.5. mysqlhotcopy
      6. B.4.6. Snapshots Using LVM
      7. B.4.7. InnoDB Hotbackup, ibbackup
    5. B.5. Monitoring
      1. B.5.1. Nagios
      2. B.5.2. Cacti
      3. B.5.3. MySQL Enterprise Monitor
    6. B.6. my.cnf Sample File
    7. B.7. Sample sphinx.conf

Product information

  • Title: Developing Web Applications with Perl, memcached, MySQL® and Apache
  • Author(s):
  • Release date: July 2009
  • Publisher(s): Wrox
  • ISBN: 9780470414644