Slides from LAX & DEN usergroup meetings
-
Upload
kevin-schroeder -
Category
Technology
-
view
1.220 -
download
0
Transcript of Slides from LAX & DEN usergroup meetings
©All rights reserved. Zend Technologies, Inc.
Bunch of user groups… Kevin Schroeder
Technology Evangelist
Zend Technologies
©All rights reserved. Zend Technologies, Inc.
About me
• Kevin Schroeder Technology Evangelist for Zend
Programmer
Sys Admin
Author• IBM i Programmer’s Guide to PHP
• You want to do WHAT with PHP? – Coming up
Race Ferraris on the weekend• My Honda has a dismal win record
©All rights reserved. Zend Technologies, Inc.
I blog at eschrade.com
Follow us!
Zend Technologies
http://twitter.com/zend
http://twitter.com/kpschrade (me!)
©All rights reserved. Zend Technologies, Inc.
A quick note on Zendcon… BE THERE!!
•Learn PHP best practices•Discover new advances •Gain new insights•Deploy and scale large PHP applications•Explore new technologies like NoSQL and Cloud Computing•Learn how to effectively leverage Zend Framework and Zend Framework 2.0
©All rights reserved. Zend Technologies, Inc.
Agenda
• You choose
• Seriously (ad hoc is fun)
• But if not Intro to Zend/Zend Products
Deployment
Unit Testing
Queuing/Scalability
©All rights reserved. Zend Technologies, Inc.
Why do we use PHP?
©All rights reserved. Zend Technologies, Inc.
What does Zend do
• Zend Framework
• Zend Studio (8.0 in public beta 1)
• Zend Server Monitoring,
Code tracing (freaking cool!!)
Job queuing
HA Session Clustering
• Zend Server Cluster Manager Does all of that in a clustered environment
©All rights reserved. Zend Technologies, Inc.
Zend Server
©All rights reserved. Zend Technologies, Inc.
Zend Server
• The primary reason to use Zend Server is insight What went wrong?
Who did it happen to?
What do I need to do to fix it?
©All rights reserved. Zend Technologies, Inc.
Why do we need diagnostic tools?
©All rights reserved. Zend Technologies, Inc.
Let’s slow that down a bit
©All rights reserved. Zend Technologies, Inc.
• There are several useful features in Zend Server 5
Code Tracing/Monitorin
gJob Queue Session
Clustering Optimizer+ Native installation
Zend Framework Apache or IIS integration Java connector
Web-based administrator
console
Debugger interface
Caching API Page cachingZend Download Server (Linux
only)
Software updates and hot fixes Technical support
©All rights reserved. Zend Technologies, Inc.
Deployment
©All rights reserved. Zend Technologies, Inc.
Before we get going
• Who here is a developer?
• Who here is a system administrator?
• Who here has an existing deployment strategy?
• Who here has edited a file in production?
• Who here has wished they hadn’t?
©All rights reserved. Zend Technologies, Inc.
Application Stages
| 15
Increasing Maturity of PHP Applications
Development Testing/QA Staging Production
©All rights reserved. Zend Technologies, Inc.
Maturity
| 16
Increasing Maturity of PHP Applications
Testing & Validating
Application
Testing & Validating
Environment
Benefit
Structure
Distinct Dev Environments
Uptime!!
Where are you?
©All rights reserved. Zend Technologies, Inc.
Application considerations
• Build the application to be aware of different environments Zend_Config_* is good at this
• Do not set the environment type in your code Environment variables can be placed in server config
• It means that you won’t accidentally keep your development settings turned on in production
• Make production your default environment Keeps accidental data leakage to a minimum
bit.ly/phpDepApp
©All rights reserved. Zend Technologies, Inc.
Deployment Option 1 – rsync
• Benefits Easy
Already installed on your system
• Drawbacks No deployment script can be run
Not integrated with either PHP or the OS
Rollbacks require rolling back the entire source server• Does not understand versioning
– One option is to move the source tree prior to the rsync
• Uses xinetd
bit.ly/phpDepRsync
©All rights reserved. Zend Technologies, Inc.
Deployment Option 2 – Source Control
• Benefits Easy
You should already be using source control
Has versioning
Can have pre/post install scripts
Easy to do automatic deployments
• Drawbacks Do you want to put details on how to access your source
code on your production box?
Requires that your source control is accessible from production
Deny access to .svn directories
bit.ly/phpDepSVN
©All rights reserved. Zend Technologies, Inc.
Deployment Option 3 – PEAR• Benefits
Designed for PHP
Very scriptable• Natural for doing things like clearing a cache
Has a better understanding of PHP
Cross platform compatible
• Drawbacks Requires admins to be familiar with PHP code
Limited to PHP deployment
Available tooling is restrictive/build your own package.xml
Define standardized locations (www, library, etc.)
bit.ly/phpDepPEAR
©All rights reserved. Zend Technologies, Inc.
Deployment Option 3 – PEAR
Creating your PEAR Channel
pear channel-discover pear.pirum-project.org
pear install pirum/Pirum-beta
vi /var/www/pear/pirum.xml
<server> <name>qa/pear</name> <summary>OurOrg PEAR channel</summary> <alias>helloworld</alias> <url>http://qa/pear/</url></server>
php ./pirum build /var/www/pear/
©All rights reserved. Zend Technologies, Inc.
Deployment Option 3 - PEAR
Creating your PEAR package
php ./build-pear.php
pear package
pirum add /var/www/pear/ HelloWorld-0.1.3.tgz
©All rights reserved. Zend Technologies, Inc.
Deploying your app
pear channel-discover qa/pear
pear config-set www_dir /var/www
pear install helloworld/HelloWorld
pear clear-cache
pear upgrade helloworld/HelloWorld
Roll Back
pear uninstall helloworld/HelloWorld
pear install helloworld/HelloWorld-0.1.3
©All rights reserved. Zend Technologies, Inc.
Deployment Option 4 - OS-based
• Benefits Easily added as part of your server deployment
• Very cloud friendly
Admins already know how to use it
Can describe OS-requirements/dependencies
Downtime limited to actual install, not network transfer time
• Drawbacks Depends on environment
Any PHP deployment scripting needs to be deployed with the application and executed in %post hook
bit.ly/phpDepYum
©All rights reserved. Zend Technologies, Inc.
Which should you use?
• Need something simple? rsync
• Need to deploy to multiple disparate platforms? PEAR
• Need to deploy internally/with minimal developer input?OS (yum/apt) If using the OS consider maintaining an internal “blessed”
repository instead of depending on the distribution
©All rights reserved. Zend Technologies, Inc.
Which should you use?
• Need something simple? rsync
• Need to deploy to multiple disparate platforms? PEAR
• Need to deploy internally/with minimal developer input?OS (yum/apt) If using the OS consider maintaining an internal “blessed”
repository instead of depending on the distribution
©All rights reserved. Zend Technologies, Inc.
Continuous Deployment
• Using automated deployment
• Very tight end-to-end integration
• Requires a lot of trust that the developers have a fully tested application w/ backend and frontend code
• Probably more work to manage if you can count the servers in your production environment with your fingers
• Could be beneficial but make sure you know what you’re doing You will need to have several testing experts
• Also…
Look at what happened the last time we gave control to the
machines
It didn’t work out so well for the humans
©All rights reserved. Zend Technologies, Inc.
Takeaways
• No need for copy-and-paste deployment
• No need for (S)FTP
• Have an easy rollback mechanism
• Prepare for errors in deployment
• Try to minimize the amount of scripting needed for deployment
• Consider using VMs on anything important to keep downtime to zero
©All rights reserved. Zend Technologies, Inc.
Unit Testing
©All rights reserved. Zend Technologies, Inc.
Unit Testing - partially stolen from Matthew Weier O’Phinney
• Why Unit Test? Simplify maintenance
It defines expectations
It describes behaviors identified by the application
It tells us when new changes break existing code and behaviors
©All rights reserved. Zend Technologies, Inc.
Terms
• Unit Test The piece of code you are testing
• Test A piece of code that calls the piece of code you’re testing
• Assertion Validating return types or results of the test
• Code Coverage A report on which lines of code have been tested
• Used to determine additional tests that need to be written
• Continuous Integration The continuous application of quality control, i.e. unit tests
©All rights reserved. Zend Technologies, Inc.
Unit Testing – What to use
• PHP testing frameworks PHPT Used by PHP, and some PEAR and independent libraries
• SimpleTest JUnit-style testing framework
• PHPUnit JUnit-style testing framework
De facto industry standard
©All rights reserved. Zend Technologies, Inc.
Writing Unit Tests
• Create a test class
• Create one or more methods describing behaviors State the behaviors in natural language
• Write code that creates the behavior(s) Write code exercising the API
• Write assertions indicating expectations
©All rights reserved. Zend Technologies, Inc.
Examples
• Example 1 – Creating a Unit Test for a model in Zend Studio
• Example 2 – Creating a Unit Test based off of Code Coverage
• Example 3 – Testing a Zend Framework controller Using Zend_Test_PHPUnit_ControllerTestCase
©All rights reserved. Zend Technologies, Inc.
Queuing/Scalable computing
©All rights reserved. Zend Technologies, Inc.
Queuing/Scalable computing
• An interesting problem Nobody has built a fully scalable application
©All rights reserved. Zend Technologies, Inc.
Typical anatomy of a PHP Application
PHP: Past and Present
| 37
Presentation
Application Control
Database Access
Business Logic
Presentation
Application Control
Business Logic
Presentation
• Not so good for defining small bits/queuable functionality
©All rights reserved. Zend Technologies, Inc.
Options
• Use Cron
• Use Gearman
• Use home-grown (don’t do this)
• Use Zend Server Job Queue
©All rights reserved. Zend Technologies, Inc.
Characteristics
• Allow for a sledgehammer to hit a machine Scalability and High Availability are yin and yang
• A site that can’t keep running is not scalable
• A site that can’t scale will fail (if it gets really popular)
©All rights reserved. Zend Technologies, Inc.
Considerations
• Waste disk space
• Control usage (don’t let users do anything they want)
• Pre-calculate as much as possible Calculate and cache/store
• Don’t scan large amounts of data
• Keep data processing off the front end servers
• Don’t just cache Don’t let it substitute for thought
Cache hit rates can be meaningless if you have hundreds of cache hits for a request
©All rights reserved. Zend Technologies, Inc.
Considerations
• Build a deployment mechanism with NO hardcoded values
• Decouple/Partition Don’t tie everything into the database
• Use queues/messaging Stomp interfaces are really good for PHP
©All rights reserved. Zend Technologies, Inc.
The Golden Rule of Scalability“It can probably wait”
©All rights reserved. Zend Technologies, Inc.
When do you not need current data
• Credit card processing?
• Request for the front page?
• Sign in?
• Viewing a shopping cart?
• Displaying a page with ads?
• Answer? Almost always
Data is “out of date” once it leaves the web server
©All rights reserved. Zend Technologies, Inc.
What could this look like?
©All rights reserved. Zend Technologies, Inc.
Let’s write some code(if we have time)
(no I’m not copping out. We’re all told to show our work in grade scool)
©All rights reserved. Zend Technologies, Inc.
Follow us!
Zend Technologies
http://twitter.com/zend
http://twitter.com/kpschrade (me!)
©All rights reserved. Zend Technologies, Inc.
Get this information and all the examples at eschrade.com…
©All rights reserved. Zend Technologies, Inc.
Remember… BE THERE!!
•Learn PHP best practices•Discover new advances •Gain new insights•Deploy and scale large PHP applications•Explore new technologies like NoSQL and Cloud Computing•Learn how to effectively leverage Zend Framework and Zend Framework 2.0