Table of Contents for
Modern PHP
Close
Version ebook
/
Retour
Modern PHP
by Josh Lockhart
Published by O'Reilly Media, Inc., 2015
Cover
nav
Modern PHP
Modern PHP
Preface
I. Language Features
1. The New PHP
2. Features
II. Good Practices
3. Standards
4. Components
5. Good Practices
III. Deployment, Testing, and Tuning
6. Hosting
7. Provisioning
8. Tuning
9. Deployment
10. Testing
11. Profiling
12. HHVM and Hack
13. Community
A. Installing PHP
B. Local Development Environments
Index
About the Author
Colophon
Preface
What You Need to Know About This Book
How This Book Is Organized
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
I. Language Features
1. The New PHP
Past
Present
Future
2. Features
Namespaces
Why We Use Namespaces
Declaration
Import and Alias
Helpful Tips
Code to an Interface
Traits
Why We Use Traits
How to Create a Trait
How to Use a Trait
Generators
Create a Generator
Use a Generator
Closures
Create
Attach State
Zend OPcache
Enable Zend OPcache
Configure Zend OPcache
Use Zend OPcache
Built-in HTTP server
Start the Server
Configure the Server
Router Scripts
Detect the Built-in Server
Drawbacks
What’s Next
II. Good Practices
3. Standards
PHP-FIG to the Rescue
Framework Interoperability
Interfaces
Autoloading
Style
What Is a PSR?
PSR-1: Basic Code Style
PSR-2: Strict Code Style
PSR-3: Logger Interface
Write a PSR-3 Logger
Use a PSR-3 Logger
PSR-4: Autoloaders
Why Autoloaders Are Important
The PSR-4 Autoloader Strategy
How to Write a PSR-4 Autoloader (and Why You Shouldn’t)
4. Components
Why Use Components?
What Are Components?
Components Versus Frameworks
Not All Frameworks Are Bad
Use the Right Tool for the Job
Find Components
Shop
Choose
Leave Feedback
Use PHP Components
How to Install Composer
How to Use Composer
Example Project
Composer and Private Repositories
Create PHP Components
Vendor and Package Names
Namespaces
Filesystem Organization
The composer.json File
The
README
file
Component Implementation
Version Control
Packagist Submission
Using the Component
5. Good Practices
Sanitize, Validate, and Escape
Sanitize Input
Validate Data
Escape Output
Passwords
Never Know User Passwords
Never Restrict User Passwords
Never Email User Passwords
Hash User Passwords with bcrypt
Password Hashing API
Password Hashing API for PHP < 5.5.0
Dates, Times, and Time Zones
Set a Default Time Zone
The DateTime Class
The DateInterval Class
The DateTimeZone Class
The DatePeriod Class
The nesbot/carbon Component
Databases
The PDO Extension
Database Connections and DSNs
Prepared Statements
Query Results
Transactions
Multibyte Strings
Character Encoding
Output UTF-8 Data
Streams
Stream Wrappers
Stream Context
Stream Filters
Custom Stream Filters
Errors and Exceptions
Exceptions
Exception Handlers
Errors
Error Handlers
Errors and Exceptions During Development
Production
III. Deployment, Testing, and Tuning
6. Hosting
Shared Server
Virtual Private Server
Dedicated Server
PaaS
Choose a Hosting Plan
7. Provisioning
Our Goal
Server Setup
First Login
Software Updates
Nonroot User
SSH Key-Pair Authentication
Disable Passwords and Root Login
PHP-FPM
Install
Global Configuration
Pool Configuration
nginx
Install
Virtual Host
Automate Server Provisioning
Delegate Server Provisioning
Further Reading
What’s Next
8. Tuning
The php.ini File
Memory
Zend OPcache
File Uploads
Max Execution Time
Session Handling
Output Buffering
Realpath Cache
Up Next
9. Deployment
Version Control
Automate Deployment
Make It Simple
Make It Predictable
Make It Reversible
Capistrano
How It Works
Install
Configure
Authenticate
Prepare the Remote Server
Capistrano Hooks
Deploy Your Application
Roll Back Your Application
Further Reading
What’s Next
10. Testing
Why Do We Test?
When Do We Test?
Before
During
After
What Do We Test?
How Do We Test?
Unit Tests
Test-Driven Development (TDD)
Behavior-Driven Development (BDD)
PHPUnit
Directory Structure
Install PHPUnit
Install Xdebug
Configure PHPUnit
The Whovian Class
The WhovianTest Test Case
Run Tests
Code Coverage
Continuous Testing with Travis CI
Setup
Run
Further Reading
What’s Next
11. Profiling
When to Use a Profiler
Types of Profilers
Xdebug
Configure
Trigger
Analyze
XHProf
Install
XHGUI
Configure
Trigger
New Relic Profiler
Blackfire Profiler
Further Reading
What’s Next
12. HHVM and Hack
HHVM
PHP at Facebook
HHVM and Zend Engine Parity
Is HHVM Right for Me?
Install
Configure
Extensions
Monitor HHVM with Supervisord
HHVM, FastCGI, and Nginx
The Hack Language
Convert PHP to Hack
What is a Type?
Static Typing
Dynamic Typing
Hack Goes Both Ways
Hack Type Checking
Hack Modes
Hack Syntax
Hack Data Structures
HHVM/Hack vs. PHP
Further Reading
13. Community
Local PUG
Conferences
Mentoring
Stay Up-to-Date
Websites
Mailing Lists
Twitter
Podcasts
Humor
A. Installing PHP
Linux
Package Managers
Ubuntu 14.04 LTS
CentOS 7
OS X
MAMP
Homebrew
Build from Source
Get the Source Code
Windows
Binaries
WAMP
Zend Server
B. Local Development Environments
VirtualBox
Vagrant
Commands
Boxes
Initialize
Provision
Synced folders
Get started
Index