Developing Easily Deployable PHP Applications
John Mertic
@2011 SugarCRM Inc. All rights reserved.
Who Am I?
John MerticContact Info
http://jmertic.wordpress.comTwitter: @[email protected] ( Sugar )[email protected] ( PHP )
I am the Community Manager for SugarCRM
http://www.sugarcrm.comhttp://developers.sugarcrm.com
Learn more about working with the SugarCRM platform during tomorrow’s session “SugarCRM: Your Next Business Application”
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 2
Buy my book!http://amzn.to/enioPV
Why deployable apps still matter
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 3
Source: http://www.flickr.com/photos/sarchi/220539933
@2011 SugarCRM Inc. All rights reserved.
What I’ll cover
Writing portable code ( or at least trying to )Enabling configuration and customization ( for users and developers )Strategies for testing and QAMaking your code perform (reasonably) well
3/24/2011 4
Writing portable code
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 5
Source: http://www.flickr.com/photos/25339258@N05/2389910825/
Define your support matrix
Operating SystemAny Linux, UNIX, OS XWindows
Web ServerApache 1.3, 2.0, 2.2IIS 6/7 using FastCGI
DatabaseMySQL 5.xSQL Server 2005, 2008Oracle 10g, 11g
PHP
5.2.x, 5.3.xSupport most common configurations options
mbstring.func_overload error_reporting = E_ALL
Require only the most mainline extensions, plus
Mbstrings ( i18n support )Imap ( mail support )Specific database extension ( mysql, mysqli, oci8, mssql, sqlsrv )
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 6
Design code that works for these platforms
Avoid writing code directly talking to the bare metal; Abstract like mad!
Use a DB abstraction layer or ORMMake sure PHP features you are using are supported across support matrix or provide an alternate implementation.Detect what else the server has for you to use, have abstraction layer to talk to them.
Example: User cache ( APC, Memcache, Wincache, etc )
Assume very little about the underlying systemExample: Treat file system as case-sensitive, and file writes are only in one area.
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 7
Example of what we have to work around
Fetching a record from a databaseMysql - mysql_fetch_assoc()Mysqli - mysqli_fetch_assoc()Mssql - mssql_fetch_assoc()Oci8 - oci_fetch_array()Sqlsrv - sqlsrv_fetch_array()
Problems we run intoEach has different input parametersWhat gets returned if no rows available?
Mysql – bool falseMysqli - nullMssql – bool falseOci8 – bool falseSqlsrv – null ( bool false if error )
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 8
Build and deploy!
We build all 3 editions of SugarCRM from 1 codebase
We add code tags around sections specific to a certain version.To test under each different edition, developers can run the build locally
We also can tag in or out features on a per edition basis.
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 9
Source: http://www.flickr.com/photos/eastcapital/4554220770/
Enabling configuration and customization
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 10
Source: http://www.flickr.com/photos/miskypig/400004362/
Making it simple yet powerful for end users
Expose configuration options thru multiple channels
Remember, not everyone has source access
Allow users to customize their UI interface easilyMake what should be simple, simple
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 11
Making it simple yet powerful for developers
Create a safe place to make customizations
Avoid painful upgradesCreate an easy to use API
Well defined and documented.Don’t break it!
Create easy to use hooks for modifying / adding functionality
Examples from SugarCRM include:Metadata driven viewsLogic Hooks
Allow for internationalization and localization
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 12
Strategies for testing and QA
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 13
Source: http://www.flickr.com/photos/cglock/386033158/
Automated Testing Tools
Jenkins (http://jenkins-ci.org/) – Extensible CI ServerRunning on every checkin
PHP lint ( php –l ) – Syntax checking for PHP source filesPHPUnit (http://www.phpunit.de/) – Unit testing framework
Runs once a daySODA – functional testing framework that leverages Watir
– SodaMachine – GUI tool for building SODA testsJMeter (http://jakarta.apache.org/jmeter/) - tool for testing a website under high load
– MeterMaid – XML language to write JMeter tests in▪ SugarMMM (MeterMaid Maker) - utility to automate
writing MeterMaid tests for SugarCRM– TidBit – tool to make huge datasets for testing
Learn more about SugarCRM’s open source tools at http://developers.sugarcrm.com/opensource
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 14
Non-automated testing
You need to actually have people use your app.We do all of the following:
Code reviewsDesign reviewsPartner and customer demosCommunity previews
Earlier the feedback, the better
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 15
Making your code perform well
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 16
Source: http://www.flickr.com/photos/tech1987/501427718/
What we do to help performance
Try to do the basic stuffAvoid writing slow codeCaching where appropriateCombine, minify, and version JS / CSS / imagesKeep SQL queries as simple as possible
Leave the rest to the Sys AdminProvide configuration options to turn off heavy featuresEnable the application to take advantage of it’s environment
Example: Using APC, memcache, Zend_Cache, wincache with little to no configuration
Provide best practices for various environments
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 17
How we gauge performance
Formal testingUse Jmeter (http://jakarta.apache.org/jmeter/) on a load test cluster to test raw response speed.Instance analysis
Monitor web server logs to look for non-cached itemsTrack slow queries
Ad-hoc testingProfile PHP execution with XDebugUse Firebug to measure CSS / JS / image payload
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 18
What are the lessons we have learned?
Define what you will support and to what extentWrite your code to be as flexible as possibleMake customizing, configuring, and extending your application not painful for users or developersTest across your support matrix, using automation when it makes senseFocus more on best practices and general performance, let admins handle it from there.
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 19
Source: http://www.flickr.com/photos/dlanod/126386070/
Questions?
Slides available on SlideShare
3/24/2011 @2011 SugarCRM Inc. All rights reserved. 20