Migration concepts for enterprise PHP applications
International PHP Conference 2008 – Spring Edition
Thorsten Rinne
Introduction

❙ Thorsten Rinne
❙ 31 years old
❙ Graduated in computer science
❙ Project manager at Mayflower GmbH, Munich
...
Summary

❙ Introduction
❙ Why upgrade?
❙ Process model
   ❙ MySQL upgrade process
   ❙ PHP upgrade process
❙ Migration
❙ C...
Introduction: Why upgrade?

❙ MySQL 4 support will end
   ❙ Active support already ended by the end of 2006
   ❙ Only exte...
Introduction: Requirements

❙ No qualitative changes like new features
❙ No technical changes like
   ❙ new database layer...
Introduction: What is porting?
                                   Innovation potential
❙ Reasons
   ❙ Most simple form of
...
Process model

❙ Reducing of complexity with a planned procedure
❙ Coverage of the complete porting
❙ Methodical descripti...
Process model: Preparations

❙ Targets
   ❙ Porting without any technical or qualitative changes
   ❙ Recovery of support ...
Process modell: Upgrading MySQL

❙ Upgrade in two steps
   ❙ MySQL 4.0 to MySQL 4.1
   ❙ MySQL 4.1 to MySQL 5.0
❙ Why two ...
Upgrade path for MySQL

❙ First dump your current database, if it‘s InnoDB. If you use
  MyISAM, just backup everything.
❙...
How to dump MySQL?

❙ Use the MySQL 4.1 mysqldump binary!
  shell> mysqldump –uroot -p
           –-database mydatabase
  ...
MySQL Pitfalls

❙ Rebuild your TIMESTAMPs, check this also in your application
❙ TIMESTAMP now has the format
  'YYYY-MM-D...
After MySQL upgrade

❙ Release the current combination
❙ PHP 4 / MySQL 5
❙ Why?
   ❙ You never find all problems during yo...
Process model: Upgrading PHP

❙ Which PHP version?
   ❙ Latest PHP 5.2 release for production, if you build by
     yourse...
Upgrade path for PHP

❙ upgrade your development machine to latest PHP 5.2
  release
❙ Test, test, test
❙ Fix your code if...
Migrate configuration files

❙ httpd.conf
   ❙ change this line:
     LoadModule php4_module php/sapi/php4apache2.dll
   ❙...
PHP 5 Pitfalls:
New reserved keyords

❙ abstract             ❙ public
❙ catch                ❙ throw
❙ clone              ...
PHP 5 Pitfalls
Constructor / Destructor

❙ PHP 4
   ❙ construct method has the name of the class
   ❙ No destruct method
❙...
PHP 5 Pitfalls
Magic methods

❙ __autoload()
❙ __call(), __callStatic() (only PHP 5.3)
❙ __construct()
❙ __destruct()
❙ __...
PHP 5 Pitfalls

❙ get_class(), get_parent_class() and
  get_class_methods() now case-sensitive
❙ __CLASS__, __METHOD__, an...
Migration strategies

❙ After the release of the PHP 5 ported application
  REFACTORING!
❙ Strategies for
   ❙ „Spaghetti ...
Migration
„Spaghetti Code“

❙ Very old code, maybe developed in the last PHP 3 century
❙ No or just minor separation of co...
Migration
„Spaghetti Code“: Strategy

❙ Identify recurring code parts and implement classes
❙ Use of standard libraries li...
Migration
„Half procedual – halb object-orientated“

❙ Code with differend quality
❙ Just a few documentation
❙ Maybe some...
Migration
„ Half procedual – halb object-orientated“: Strategy

❙ Add inline documentation for all classes and methods
❙ I...
Migration
PHP 4 OOP

❙ Application was developed object-orientated in PHP 4
❙ Using of
   ❙ PHP 4 references
   ❙ Re-decla...
Migration
PHP 4 OOP: Strategy

❙ Maybe you‘re lucky and there are no problems. Maybe.
❙ If you see problems, they are fata...
Conclusion

❙ Migration is always possible
❙ Migration can be hard, but usually it isn‘t! ☺
❙ Don‘t shoot yourself in the ...
Questions and answers




                        „Migration concepts for enterprise
                        PHP applicati...
Thank you very much!

Thorsten Rinne, Dipl.-Inf. (FH)
Mayflower GmbH
Mannhardtstraße 6
D-80538 München
Germany
+49 (89) 24...
Upcoming SlideShare
Loading in …5
×

Migration Concepts For Enterprise PHP Applications

3,824
-1

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,824
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
47
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Migration Concepts For Enterprise PHP Applications

  1. 1. Migration concepts for enterprise PHP applications International PHP Conference 2008 – Spring Edition Thorsten Rinne
  2. 2. Introduction ❙ Thorsten Rinne ❙ 31 years old ❙ Graduated in computer science ❙ Project manager at Mayflower GmbH, Munich ❙ Reporting applications ❙ Critical bank applications ❙ PHP Consulting ❙ PHP software development since 1999 ❙ Founder and main developer of Open Source FAQ- management software phpMyFAQ since 2001 ❙ Zend Certified Engineer (PHP 5) „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 2
  3. 3. Summary ❙ Introduction ❙ Why upgrade? ❙ Process model ❙ MySQL upgrade process ❙ PHP upgrade process ❙ Migration ❙ Conclusion ❙ Questions and answers „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 3
  4. 4. Introduction: Why upgrade? ❙ MySQL 4 support will end ❙ Active support already ended by the end of 2006 ❙ Only extended support until 2008 for MySQL 4.0 and 2009 for MySQL 4.1 ❙ MySQL 5 has more and advanced features like stored procedures, trigger, better SQL support ❙ PHP 4 support will end ❙ PHP 4 is dead, dead, dead ❙ Only security relevant fixes until 2008-08-08 ❙ PHP 5.2 is faster and more stable than every PHP 4 version „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 4
  5. 5. Introduction: Requirements ❙ No qualitative changes like new features ❙ No technical changes like ❙ new database layer ❙ new template engine ❙ Using new PHP 5 features ❙ No influences for productive services like ❙ External systems ❙ End user frontends ❙ Minimization of time and effort „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 5
  6. 6. Introduction: What is porting? Innovation potential ❙ Reasons ❙ Most simple form of migration ive sit Rewrite ❙ Manageble risks po ❙ Small complexity because of the lack of qualitive and Reengineering technical changes e tiv ❙ Requirement ga ne ❙ Minor differences between Porting current and future application platform complexity „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 6
  7. 7. Process model ❙ Reducing of complexity with a planned procedure ❙ Coverage of the complete porting ❙ Methodical description of the process ❙ Tool support „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 7
  8. 8. Process model: Preparations ❙ Targets ❙ Porting without any technical or qualitative changes ❙ Recovery of support (MySQL/PHP) ❙ Minimizing the interferences of services and reduction of change times ❙ Interferences ❙ Porting problems between MySQL and PHP versions ❙ Application complexity ❙ missing documentation and missing contact persons ❙ Communication between all team members „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 8
  9. 9. Process modell: Upgrading MySQL ❙ Upgrade in two steps ❙ MySQL 4.0 to MySQL 4.1 ❙ MySQL 4.1 to MySQL 5.0 ❙ Why two steps? ❙ Big changes between 4.0 and 4.1 ❙ Password changes ❙ Character sets ❙ Collations ❙ Many minor BC breaks „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 9
  10. 10. Upgrade path for MySQL ❙ First dump your current database, if it‘s InnoDB. If you use MyISAM, just backup everything. ❙ upgrade your development machine ❙ Reload your tables ❙ Test, test, test with MySQL 5.0 ❙ Fix your queries and application if you have problems ❙ Use the STRICT MODE in MySQL 5.0 ❙ Test, test, test with MySQL 5.0 ❙ Upgrade your production machine ❙ Reload your production database „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 10
  11. 11. How to dump MySQL? ❙ Use the MySQL 4.1 mysqldump binary! shell> mysqldump –uroot -p –-database mydatabase --single-transaction --default-character-set=utf-8 --disable-keys --extended-insert | bzip2 –c > backup.sql.bz2 Warning: This can lock all tables! ❙ Fix the password column in the MySQL user table shell> mysql_fix_privilege_tables --password=root_password „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 11
  12. 12. MySQL Pitfalls ❙ Rebuild your TIMESTAMPs, check this also in your application ❙ TIMESTAMP now has the format 'YYYY-MM-DD HH:MM:SS' ❙ DECIMAL(14,2) in MySQL 4.0 is not the same as DECIMAL(14,2) in MySQL 4.1/5.0 ❙ using DECIMAL(10,5): 100000 will be 99999.99999 ❙ using DECIMAL(11,5): 100000 will be 100000.00000 ❙ New reserved words ❙ SQL2003 standard for your SQL queries with natural JOINs and JOINs with USING may produce different results ❙ http://dev.mysql.com/doc/refman/5.0/en/upgrading-from- 4-1.html „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 12
  13. 13. After MySQL upgrade ❙ Release the current combination ❙ PHP 4 / MySQL 5 ❙ Why? ❙ You never find all problems during your tests ❙ PHP porting may took longer than the MySQL porting ❙ Increase your experience with MySQL 5 ❙ Prepare the PHP 5 update „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 13
  14. 14. Process model: Upgrading PHP ❙ Which PHP version? ❙ Latest PHP 5.2 release for production, if you build by yourself or current PHP 5.2 package from your Linux/Unix/*BSD/Solaris distribution ❙ Testing with PHP 5.3-dev if you have time and money ❙ Please don‘t use ❙ PHP 5.0.x ❙ PHP 5.1.x ❙ PHP 6.0.0-dev „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 14
  15. 15. Upgrade path for PHP ❙ upgrade your development machine to latest PHP 5.2 release ❙ Test, test, test ❙ Fix your code if you have problems ❙ register_globals = off ❙ error_reporting = E_ALL & E_STRICT ❙ display_errors = on ❙ log_errors = on ❙ Test, test, test ❙ Upgrade your production machine ❙ Release your ported application „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 15
  16. 16. Migrate configuration files ❙ httpd.conf ❙ change this line: LoadModule php4_module php/sapi/php4apache2.dll ❙ with this one: LoadModule php5_module /php/php5apache2.dll ❙ php.ini ❙ You should use the php.ini-recommended file, but check, if you need magic quotes on…. Otherwise your application could be insecure! „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 16
  17. 17. PHP 5 Pitfalls: New reserved keyords ❙ abstract ❙ public ❙ catch ❙ throw ❙ clone ❙ try ❙ extends ❙ use ❙ final ❙ namespace ❙ implements ❙ instanceof ❙ interface ❙ goto ❙ private ❙ protected „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 17
  18. 18. PHP 5 Pitfalls Constructor / Destructor ❙ PHP 4 ❙ construct method has the name of the class ❙ No destruct method ❙ PHP 5 ❙ construct method: __construct() ❙ If not available, fallback to PHP4 handling ❙ destruct method: __destruct() ❙ Executed at the end of the request „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 18
  19. 19. PHP 5 Pitfalls Magic methods ❙ __autoload() ❙ __call(), __callStatic() (only PHP 5.3) ❙ __construct() ❙ __destruct() ❙ __get() ❙ __isset() ❙ __set() ❙ __set_state() ❙ __sleep() ❙ __toString() ❙ __unset() ❙ __wakeup() „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 19
  20. 20. PHP 5 Pitfalls ❙ get_class(), get_parent_class() and get_class_methods() now case-sensitive ❙ __CLASS__, __METHOD__, and __FUNCTION__ are also case-sensitive ❙ Objects are referenced by handle, and not by value ❙ Objects aren’t primitive types like in PHP 4 ❙ If you need a copy of a object, use __clone() ❙ Re-declaration of $this isn’t allowed anymore ❙ === operator is more strict than it was in PHP 4 ❙ __call()/__set()/__get() are different in PHP 4 ❙ Don’t use zend.ze1.compatibility_mode! ❙ Use instanceof instead of is_a() „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 20
  21. 21. Migration strategies ❙ After the release of the PHP 5 ported application REFACTORING! ❙ Strategies for ❙ „Spaghetti code“ ❙ Half procedural – half object-orientated ❙ PHP 4 OOP ❙ Please don‘t try a complete rewrite ❙ Too expensive ❙ Takes too long ❙ Joel on software: „Things You Should Never Do “ „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 21
  22. 22. Migration „Spaghetti Code“ ❙ Very old code, maybe developed in the last PHP 3 century ❙ No or just minor separation of code and layout ❙ No use of libraries like PEAR, Zend Framework or eZ components ❙ No documentation ❙ No tests „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 22
  23. 23. Migration „Spaghetti Code“: Strategy ❙ Identify recurring code parts and implement classes ❙ Use of standard libraries like Zend Framework, eZ components or PEAR ❙ Add inline documentation ❙ Fix your coding styles ❙ Add unittests for the new, refactored backend ❙ Add Selenium tests for the frontend „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 23
  24. 24. Migration „Half procedual – halb object-orientated“ ❙ Code with differend quality ❙ Just a few documentation ❙ Maybe some tests ❙ „the typical current PHP 4 project“ ☺ „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 24
  25. 25. Migration „ Half procedual – halb object-orientated“: Strategy ❙ Add inline documentation for all classes and methods ❙ Improve the re-using of duplicate code ❙ Add unittests and Selenium tests ❙ Improve every code part with PHP 5 functions, for example using file_put_contents() instead of fopen(), fwrite(), and fclose(). „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 25
  26. 26. Migration PHP 4 OOP ❙ Application was developed object-orientated in PHP 4 ❙ Using of ❙ PHP 4 references ❙ Re-declaration of $this „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 26
  27. 27. Migration PHP 4 OOP: Strategy ❙ Maybe you‘re lucky and there are no problems. Maybe. ❙ If you see problems, they are fatal errors like ❙ Objects are referenced by value ❙ $foo =& new Foo(); ❙ Solution: ❙ Implement unittests ❙ Use standard APIs ❙ Fix the PHP 5 problems „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 27
  28. 28. Conclusion ❙ Migration is always possible ❙ Migration can be hard, but usually it isn‘t! ☺ ❙ Don‘t shoot yourself in the foot with the migration ❙ First upgrade MySQL ❙ Then upgrade PHP and fix your application ❙ Then do the cleanup for a better future ☺ ❙ Stay current in the future and do always small steps ❙ Keep PHP 5.3 and PHP 5.4 in mind! „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 28
  29. 29. Questions and answers „Migration concepts for enterprise PHP applications“ © MAYFLOWER GmbH 2008 29
  30. 30. Thank you very much! Thorsten Rinne, Dipl.-Inf. (FH) Mayflower GmbH Mannhardtstraße 6 D-80538 München Germany +49 (89) 24 20 54 – 31 thorsten.rinne@mayflower.de

×