PacktLib: PHP and MongoDB Web Development Beginner’s Guide

PHP and MongoDB Web Development

Credits

About the Author

About the Reviewers

www.PacktPub.com

Preface

Getting Started with MongoDB

The NoSQL movement

MongoDB A document-based NoSQL database

Downloading, installing, and running MongoDB

Time for action - downloading and running MongoDB on Windows

Time for action - downloading and running MongoDB on Linux

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

Connecting to the MongoDB server from PHP

Time for action - creating a connection to the MongoDB server from PHP

Summary

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

Querying documents in a collection

Time for action - retrieving articles from a database

Doing advanced queries in MongoDB

Time for action - building the Blog Dashboard

Updating documents in MongoDB

Time for action - building the Blog Editor

Deleting documents in MongoDB

Time for action - deleting blog posts

Managing relationships between documents

Time for action - posting comments to blog posts

Summary

Building a Session Manager

Understanding HTTP sessions

Understanding PHP native session handling

Time for action - testing native PHP session handling

Implementing session handling with MongoDB

Time for action - building the SessionManager class

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

Summary

Aggregation Queries

Generating sample data

Time for action - generating sample data

Understanding MapReduce

Performing MapReduce in MongoDB

Time for action - counting the number of articles for each author

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

Listing distinct values for a field

Time for action - listing distinct categories of articles

Counting documents with count()

Summary

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

Extracting analytics data with MapReduce

Time for action - finding total views and average response time per blog post

Real-time analytics using MongoDB

Time for action - building a real-time page visit counter

Summary

Using MongoDB with Relational Databases

The motivation behind using MongoDB and an RDBMS together

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

Using MongoDB for data archiving

Time for action - archiving old sales records in MongoDB

Storing metadata in MongoDB

Time for action - using MongoDB to store customer metadata

Problems with using MongoDB and RDBMS together

Summary

Handling Large Files with GridFS

What is GridFS?

Storing files in GridFS

Time for action - uploading images to GridFS

Serving files from GridFS

Time for action - serving images from GridFS

Reading files in chunks

Time for action - reading images in chunks

When should you not use GridFS

Summary

Building Location-aware Web Applications with MongoDB and PHP

A geolocation primer

Detecting the location of a web page visitor

Time for action - detecting location with W3C API

Geospatial indexing

Time for action - creating geospatial indexes

Performing location queries

Time for action - finding restaurants near your location

Geospatial haystack indexing

Time for action - finding nearby restaurants that serve burgers

Summary

Improving Security and Performance

Enhancing query performance using indexes

Time for action - creating an index on a MongoDB collection

Optimizing queries

Securing MongoDB

Time for action - adding user authentication in MongoDB

Ensuring data durability

Summary

Easy MongoDB Administration with RockMongo and phpMoAdmin

Administering MongoDB with RockMongo

Time for action - installing RockMongo on your computer

Using phpMoAdmin to administer MongoDB

Time for action - installing phpMoAdmin on your computer

RockMongo versus phpMoAdmin

Summary

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers