OK, so everyone else has pretty much covered the arguments for "don't do it, run" and for "re-write it". But assuming that you either
a) have to maintain it anyway (can't afford to lose job etc.)
or
b) are going to re-write it but don't have a definte spec to know what it has to do
then you are going to need to try and understand the code base. Here are some PHP specific tools to help you.
- Use XHGUI[1] (which is a fork of Facebooks XHProf) to profile the code as it runs. It can draw call-graphs for you (if you have Graphviz installed) which will help you to visuallise the code flow.
- Use PHPdoc[2] to generate API docs. This will help you get a simplified overview of the code to use as a reference.
- Use Xdebug[3] as you make changes and execute code to get more insight into how it is running and to trace variables etc. through the execution. You can use KCacheGrind [4] to visualise the output of Xdebug.
- Use a staging/development environment for everything you do with this code, and don't push any changes into to production until you really, really have to. When you do, use version control (e.g. Git, SVN etc.) and use an automated build system (Phing[5] is a great PHP specific one) to try and keep everything consistent.
Good luck! Quick plug : I'm currently writing a book [6] about PHP development (called PHP Everywhere : Programming beyond the web with PHP) which covers the tools above (albeit not for the kind of job you are taking on!). The one small mercy you may have when tackling a project like this is that it is written in PHP. PHP is usually quite a verbose language, which while it doesn't always produce sexy code, does mean that its straight forward to read and understand (at the local level!). An extra space here and there doesn't usually alter the meaning of the code as it does in some languages!
Hey RobAley, thanks a lot for the tool recommendations... also big thanks for the person who suggested SONAR+PHP, will definitely look at that too.
I was planning on using phpdoc and xdebug, but haven't ever looked at XHGUI. Is it significantly different from xdebug? At first glance there seems to be a fair bit of overlap in terms of functionality.
There is a fair amount of overlap in what they do, the main variation is in the interfaces and how the information is presented. I tend to use one or the other depending on the task at hand. They're both of good "pedigree", xdebug has been around now for about 10 years I think and so has a good amount of history behind it, and XHProf which XHGui is based on was developed by Facebook and used against their code base which is probably somewhat larger than yours (though hopefully better written!). At then end of the day they're both pretty easy to get up and running (and of course they're free), so I would suggest giving them both a test run and see which you prefer the feel of and which better suits your needs in terms of the information it gives you for your task. Given that you look like you will need all the help you can get, you might even end up using multiple tools like this to get as much insight into the code as you can. If you do, be aware that they can often interfere with each other (or so I've read, I've never tried those two on the same code base at the same time) so you might need to deploy them on separate virtualised but identical environments with the same code.
Edit: Just to say, I usually use XHGui for profiling existing code and code in production, and xdebug for profiling changes to code and code under development. But thats just because thats how the tools "feel" right to me, and there's no reason why you can't do both with both.
Comments
OK, so everyone else has pretty much covered the arguments for "don't do it, run" and for "re-write it". But assuming that you either
a) have to maintain it anyway (can't afford to lose job etc.)
or
b) are going to re-write it but don't have a definte spec to know what it has to do
then you are going to need to try and understand the code base. Here are some PHP specific tools to help you.
- Use XHGUI[1] (which is a fork of Facebooks XHProf) to profile the code as it runs. It can draw call-graphs for you (if you have Graphviz installed) which will help you to visuallise the code flow.
- Use PHPdoc[2] to generate API docs. This will help you get a simplified overview of the code to use as a reference.
- Use Xdebug[3] as you make changes and execute code to get more insight into how it is running and to trace variables etc. through the execution. You can use KCacheGrind [4] to visualise the output of Xdebug.
- Use a staging/development environment for everything you do with this code, and don't push any changes into to production until you really, really have to. When you do, use version control (e.g. Git, SVN etc.) and use an automated build system (Phing[5] is a great PHP specific one) to try and keep everything consistent.
Good luck! Quick plug : I'm currently writing a book [6] about PHP development (called PHP Everywhere : Programming beyond the web with PHP) which covers the tools above (albeit not for the kind of job you are taking on!). The one small mercy you may have when tackling a project like this is that it is written in PHP. PHP is usually quite a verbose language, which while it doesn't always produce sexy code, does mean that its straight forward to read and understand (at the local level!). An extra space here and there doesn't usually alter the meaning of the code as it does in some languages!
[1] https://github.com/preinheimer/xhprof [2] http://www.phpdoc.org/ [3] http://www.xdebug.org/ [4] http://kcachegrind.sourceforge.net [5] http://www.phing.info/ [6] http://leanpub.com/php
Hey RobAley, thanks a lot for the tool recommendations... also big thanks for the person who suggested SONAR+PHP, will definitely look at that too.
I was planning on using phpdoc and xdebug, but haven't ever looked at XHGUI. Is it significantly different from xdebug? At first glance there seems to be a fair bit of overlap in terms of functionality.
There is a fair amount of overlap in what they do, the main variation is in the interfaces and how the information is presented. I tend to use one or the other depending on the task at hand. They're both of good "pedigree", xdebug has been around now for about 10 years I think and so has a good amount of history behind it, and XHProf which XHGui is based on was developed by Facebook and used against their code base which is probably somewhat larger than yours (though hopefully better written!). At then end of the day they're both pretty easy to get up and running (and of course they're free), so I would suggest giving them both a test run and see which you prefer the feel of and which better suits your needs in terms of the information it gives you for your task. Given that you look like you will need all the help you can get, you might even end up using multiple tools like this to get as much insight into the code as you can. If you do, be aware that they can often interfere with each other (or so I've read, I've never tried those two on the same code base at the same time) so you might need to deploy them on separate virtualised but identical environments with the same code.
Edit: Just to say, I usually use XHGui for profiling existing code and code in production, and xdebug for profiling changes to code and code under development. But thats just because thats how the tools "feel" right to me, and there's no reason why you can't do both with both.