Powerful Google developer tools for immediate impact! (2023-24 C)
Slides from LAX & DEN usergroup meetings
1. Bunch of user groups… Kevin Schroeder Technology Evangelist Zend Technologies
2. 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
3. I blog at eschrade.com Follow us! Zend Technologies http://twitter.com/zend http://twitter.com/kpschrade (me!)
11. 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
18. 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?
19. Application Stages | 15 Increasing Maturity of PHP Applications Development Testing/QA Staging Production
20. Maturity | 16 Increasing Maturity of PHP Applications Uptime!! Testing & Validating Environment Testing & Validating Application Distinct Dev Environments Benefit Where are you? Structure
21. 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
22. 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
23. 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
24. 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
27. 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
28. 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
29. 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
30. 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
31. 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
32. 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
34. 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
35. 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
36. 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
37. 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
38. 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
41. Typical anatomy of a PHP Application PHP: Past and Present Presentation Not so good for defining small bits/queuable functionality Application Control Database Access Business Logic Presentation Application Control Business Logic Presentation | 37
42. Options Use Cron Use Gearman Use home-grown (don’t do this) Use Zend Server Job Queue
43. 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)
44. 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
47. 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