PHP and MongoDB Web Development Beginner’s Guide


PHP and MongoDB Web Development Beginner’s Guide
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
$22.94
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
$44.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Learn to build PHP-powered dynamic web applications using MongoDB as the data backend
  • Handle user sessions, store real-time site analytics, build location-aware web apps, and much more, all using MongoDB and PHP
  • Full of step-by-step instructions and practical examples, along with challenges to test and improve your knowledge

Book Details

Language : English
Paperback : 292 pages [ 235mm x 191mm ]
Release Date : November 2011
ISBN : 1849513627
ISBN 13 : 9781849513623
Author(s) : Rubayeet Islam
Topics and Technologies : All Books, Web Development, Beginner's Guides, Open Source, PHP

Table of Contents

Preface
Chapter 1: Getting Started with MongoDB
Chapter 2: Building your First MongoDB Powered Web App
Chapter 3: Building a Session Manager
Chapter 4: Aggregation Queries
Chapter 5: Web Analytics using MongoDB
Chapter 6: Using MongoDB with Relational Databases
Chapter 7: Handling Large Files with GridFS
Chapter 8: Building Location-aware Web Applications with MongoDB and PHP
Chapter 9: Improving Security and Performance
Chapter 10: Easy MongoDB Administration with RockMongo and phpMoAdmin
Pop Quiz Answers
Index
  • Chapter 1: Getting Started with MongoDB
    • The NoSQL movement
      • Types of NoSQL databases
    • MongoDB – A document-based NoSQL database
      • Why MongoDB?
      • Who is using MongoDB?
      • MongoDB concepts—Databases, collections, and documents
        • Anatomy of document
        • BSON—The data exchange format for MongoDB
        • Similarity with relational databases
    • Downloading, installing, and running MongoDB
      • System requirements
    • Time for action – downloading and running MongoDB on Windows
      • Installing the 64-bit version
    • Time for action – downloading and running MongoDB on Linux
      • Installing MongoDB on OS X
      • Configuring MongoDB
        • Command-line parameters
        • File-based configuration
      • Stopping MongoDB
        • Hitting Control + C
        • From the mongo shell
        • Sending INT or TERM signal in UNIX
    • Creating databases, collections, and documents
    • Time for Action – creating databases, collections, and documents
    • Installing the PHP driver for MongoDB
    • Time for Action – installing PHP driver for MongoDB on Windows
      • Installing the PHP-MongoDB driver on Unix
    • Connecting to the MongoDB server from PHP
      • Creating a PHP-Mongo connection
    • Time for action – creating a connection to the MongoDB server from PHP
      • Configuring the PHP-MongoDB connection
      • Specifying timeout for the connection attempt
    • Summary
    • Chapter 2: Building your First MongoDB Powered Web App
      • A MongoDB powered blog
      • Have the MongoDB server running
      • Inserting documents in MongoDB
      • Time for action – building the Blog Post Creator
        • Creating databases and collections implicitly
        • Performing 'safe' inserts
          • Benefits of safe inserts
        • Specifying a timeout on insert
        • Setting the user generated _id
        • The MongoDate object
      • Querying documents in a collection
      • Time for action – retrieving articles from a database
        • The Mongo Query Language
          • The MongoCursor object
          • Conditional Queries
      • Doing advanced queries in MongoDB
      • Time for action – building the Blog Dashboard
        • Returning a subset of fields
        • Sorting the query results
        • Using count, skip, and limit
        • Performing range queries on dates
      • Updating documents in MongoDB
      • Time for action – building the Blog Editor
        • Optional arguments to the update method
        • Performing 'upsert'
        • Using update versus using save
        • Using modifier operations
          • Setting with $set
          • Incrementing with $inc
          • Deleting fields with $unset
          • Renaming fields with $rename
      • Deleting documents in MongoDB
      • Time for action – deleting blog posts
        • Optional arguments to remove
      • Managing relationships between documents
        • Embedded documents
        • Referenced documents
      • Time for action – posting comments to blog posts
        • Embedded versus referenced – Which one to use?
          • Querying embedded objects
      • Summary
      • Chapter 3: Building a Session Manager
        • Understanding HTTP sessions
        • Understanding PHP native session handling
        • Time for action – testing native PHP session handling
          • Limitations of native PHP session handling
        • Implementing session handling with MongoDB
          • Extending session handling with session_set_save_handler
          • The SessionManager class
        • Time for action – building the SessionManager class
          • How the SessionManager works
            • The constructor
            • The open and close methods
            • The read method
            • The write method
            • The destroy method
            • The gc method
        • Putting the SessionManager in action
        • Time for action – putting SessionManager into action
        • Building the user authentication module
        • Time for action – building the User class
        • Creating the login, logout, and user profile page
        • Time for action – creating the login, logout, and profile page
        • Using good session practices
          • Setting low expiry times of session cookies
          • Using session timeouts
          • Setting proper domains for session cookies
          • Checking for browser consistency
        • Summary
        • Chapter 4: Aggregation Queries
          • Generating sample data
          • Time for action – generating sample data
          • Understanding MapReduce
            • Visualizing MapReduce
          • Performing MapReduce in MongoDB
          • Time for action – counting the number of articles for each author
            • Defining the Map function
            • Defining the Reduce function
            • Applying the Map and Reduce
            • Viewing the results
            • Performing MapReduce on a subset of the collection
            • Concurrency
          • Performing MongoDB MapReduce within PHP
          • Time for action – creating a tag cloud
          • Performing aggregation using group()
          • Time for action – calculating the average rating per author
            • Grouping by custom keys
            • MapReduce versus group()
          • Listing distinct values for a field
          • Time for action – listing distinct categories of articles
            • Using distinct() in mongo shell
          • Counting documents with count()
          • Summary
          • Chapter 5: Web Analytics using MongoDB
            • Why MongoDB is a good choice as a web analytics backend
            • Logging with MongoDB
            • Time for action – logging page visits with MongoDB
              • Capped collections
                • Sorting in natural order
                • Updating and deleting documents in a capped collection
                • Specifying the size of a regular collection
                • Convert a regular collection to a capped one
            • Extracting analytics data with MapReduce
            • Time for action – finding total views and average response time per blog post
              • The map, reduce, and finalize functions
              • Displaying the result
                • Running MapReduce in real time versus running it in the background
            • Real-time analytics using MongoDB
            • Time for action – building a real-time page visit counter
            • Summary
            • Chapter 6: Using MongoDB with Relational Databases
              • The motivation behind using MongoDB and an RDBMS together
                • Potential use cases
              • Defining the relational model
              • Time for action – creating the database in MySQL
              • Caching aggregation results in MongoDB
              • Time for action – storing the daily sales history of products in MongoDB
              • Benefits of caching queries in MongoDB
                • Storing results of expensive JOINs
              • Using MongoDB for data archiving
              • Time for action – archiving old sales records in MongoDB
                • Challenges in archiving and migration
                  • Dealing with foreign key constraints
                  • Preserving data types
              • Storing metadata in MongoDB
              • Time for action – using MongoDB to store customer metadata
              • Problems with using MongoDB and RDBMS together
              • Summary
              • Chapter 7: Handling Large Files with GridFS
                • What is GridFS?
                  • The rationale of GridFS
                  • The specification
                  • Advantages over the filesystem
                • Storing files in GridFS
                • Time for action – uploading images to GridFS
                  • Looking under the hood
                • Serving files from GridFS
                • Time for action – serving images from GridFS
                  • Updating metdata of a file
                  • Deleting files
                • Reading files in chunks
                • Time for action – reading images in chunks
                • When should you not use GridFS
                • Summary
                • Chapter 8: Building Location-aware Web Applications with MongoDB and PHP
                  • A geolocation primer
                    • Methods to determine location
                  • Detecting the location of a web page visitor
                    • The W3C Geolocation API
                      • Browsers that support geolocation
                  • Time for action – detecting location with W3C API
                    • The Geolocation object
                      • The getCurrentPosition() method
                    • Drawing the map using the Google Maps API
                  • Geospatial indexing
                  • Time for action – creating geospatial indexes
                    • Geospatial indexing – Important things to know
                  • Performing location queries
                  • Time for action – finding restaurants near your location
                    • The geoNear() command
                    • Bounded queries
                  • Geospatial haystack indexing
                  • Time for action – finding nearby restaurants that serve burgers
                  • Summary
                  • Chapter 9: Improving Security and Performance
                    • Enhancing query performance using indexes
                    • Time for action – creating an index on a MongoDB collection
                      • The _id index
                      • Unique indexes
                      • Compound keys indexes
                      • Indexing embedded document fields
                      • Indexing array fields
                      • Deleting indexes
                      • When indexing cannot be used
                      • Indexing guidelines
                        • Choose the keys wisely
                        • Keep an eye on the index size
                        • Avoid using low-selectivity single key indexes
                        • Be aware of indexing costs
                        • On a live database, run indexing in the background
                    • Optimizing queries
                      • Explaining queries using explain()
                        • Optimization rules
                      • Using hint()
                      • Profiling queries
                        • Understanding the output
                        • Optimization rules
                    • Securing MongoDB
                    • Time for action – adding user authentication in MongoDB
                      • Creating an admin user
                      • Creating regular user
                      • Viewing, changing, and deleting user accounts
                      • User authentication through PHP driver
                      • Filtering user input
                      • Running MongoDB server in a secure environment
                    • Ensuring data durability
                      • Journaling
                        • Performance
                        • Using fsync
                      • Replication
                    • Summary
                    • Chapter 10: Easy MongoDB Administration with RockMongo and phpMoAdmin
                      • Administering MongoDB with RockMongo
                      • Time for action – installing RockMongo on your computer
                        • Exploring data with RockMongo
                          • Querying
                          • Updating, deleting, and creating documents
                        • Importing and exporting data
                        • Viewing stats
                        • Miscellaneous
                      • Using phpMoAdmin to administer MongoDB
                      • Time for action – installing phpMoAdmin on your computer
                        • Viewing databases and collections
                        • Querying documents
                        • Saving and deleting objects
                        • Importing and exporting data
                        • Viewing stats
                        • Other features
                      • RockMongo versus phpMoAdmin
                        • The verdict
                      • Summary
                      • Pop Quiz Answers
                        • Chapter 1, Getting Started with MongoDB
                        • Chapter 2, Building your First MongoDB Powered Web App
                        • Chapter 3, Building a Session Manager
                        • Chapter 4, Aggregation Queries
                        • Chapter 5, Web Analytics using MongoDB
                        • Chapter 7, Handling Large Files with GridFS
                        • Chapter 8, Building Location-aware Web Applications with MongoDB and PHP
                        • Chapter 9, Improving Security and Performance

                        Rubayeet Islam

                        Rubayeet Islam is a software developer with over four years of experience in large-scale web application development on open-source technology stacks (LAMP, Python/Django, Ruby on Rails). He is currently involved in developing cloud-based distributed software that uses MongoDB as its analytics and metadata back-end. He has also spoken in seminars to promote the use of MongoDB and NoSQL databases in general. He graduated from University of Dhaka with BS in Computer Science and Engineering.
                        Sorry, we don't have any reviews for this title yet.

                        Code Downloads

                        Download the code and support files for this book.


                        Submit Errata

                        Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                        Errata

                        - 4 submitted: last submission 20 Jul 2012

                        Errata type: Code | Page number: 186

                            if(isset($error['err'])) {
                        should be
                            if(!isset($error['err'])) {

                        Errata type: Code | Page number: 206

                            //callback function for Ajax, marks each nearbu restaurant
                        should be
                            //callback function for Ajax, marks each nearby restaurant

                        Errata type: Code | Page number: 179

                           <h3/>
                        should be
                          </h3>

                        Errata type: Code | Page number: 170

                        In the first sentence of the third paragraph there is a missing underscore
                            The magic method _get() ...
                        should be
                            The magic method __get() ...
                        Also in the second sentence of the same paragraph there is a missing underscore
                            The _set() method ...
                        should be
                            The __set() method ...

                        Sample chapters

                        You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                        Frequently bought together

                        PHP and MongoDB Web Development Beginner’s Guide +    HTML5 Enterprise Application Development =
                        50% Off
                        the second eBook
                        Price for both: €30.90

                        Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                        What you will learn from this book

                        • Get MongoDB up and running on the machine (Windows/Mac/Linux)
                        • Build a PHP-powered website with MongoDB as the data storage
                        • Handle HTTP sessions with MongoDB
                        • Store website analytics data in real time
                        • Process large datasets with MapReduce
                        • Use MongoDB to supplement your existing relational database– build data archives, cache tiers, store results of expensive SQL queries in MongoDB
                        • Build location-aware web applications
                        • Optimize MongoDB for better performance and security

                         

                        In Detail

                        With the rise of Web 2.0, the need for a highly scalable database, capable of storing diverse user-generated content is increasing. MongoDB, an open-source, non-relational database has stepped up to meet this demand and is being used in some of the most popular websites in the world. MongoDB is one of the NoSQL databases which is gaining popularity for developing PHP Web 2.0 applications.

                        PHP and MongoDB Web Development Beginner’s Guide is a fast-paced, hands-on guide to get started with web application development using PHP and MongoDB. The book follows a “Code first, explain later” approach, using practical examples in PHP to demonstrate unique features of MongoDB. It does not overwhelm you with information (or starve you of it), but gives you enough to get a solid practical grasp on the concepts.

                        The book starts by introducing the underlying concepts of MongoDB. Each chapter contains practical examples in PHP that teache specific features of the database.
                        The book teaches you to build a blogging application, handle user sessions and authentication, and perform aggregation with MapReduce. You will learn unique MongoDB features and solve interesting problems like real-time analytics, location-aware web apps etc. You will be guided to use MongoDB alongside MySQL to build a diverse data back-end.

                        With its concise coverage of concepts and numerous practical examples, PHP and MongoDB Web Development Beginner’s Guide is the right choice for the PHP developer to get started with learning MongoDB.

                        Approach

                        The book follows a “Code first, explain later” approach, using practical examples in PHP to demonstrate unique features of MongoDB. This book is packed with step-by-step instructions and practical examples, along with challenges to test and improve your knowledge.

                        Who this book is for

                        This book assumes that you are experienced in web application development using PHP, HTML, and CSS. Having working knowledge of using a relational database system such as MySQL will help you grasp some of the concepts quicker, but it is not strictly mandatory. No prior knowledge of MongoDB is required.

                        Code Download and Errata
                        Packt Anytime, Anywhere
                        Register Books
                        Print Upgrades
                        eBook Downloads
                        Video Support
                        Contact Us
                        Awards Voting Nominations Previous Winners
                        Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                        Resources
                        Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software