PHP Reverse Engineering – How to Reverse Engineer a PHP Application Without Reading Code

PHPreverse-engineering

I have this new customer, that has this PHP App. It was written by a single developer that wanted to "make yet another framework" back in 2005. About 3 Years later the developer left the company, and with him all Knowledge on what this thing is actually doing.

Now, as the App already went in production the manager just hired a few more developers / freelancers (that are not available anymore too) to fix bugs here and there and develop some more functionality. Some tried to follow the undocumented guidelines of the software, some did not.

You might be able to imagine how the code looks today … its an utter mess!

I talked to the manager and told him what I think of his software and managed to get him to realy think about rewriting the damn thing.

But here comes my problem: To be able to estimate the effort needed to rewrite I would need to know what the thing is doing. The manager can tell me from his perspective what it's doing but there is just no technical knowledge about it. And as with all software that grew over years there are these "special edge cases".

Basically my idea is "record/log" the live system for a few weeks to actually get a technical, somewhat complete conclusion of what this thing is doing most of the time and what are the things that rarely get touched/used. E.g. what was the Request and what route did it go to render the results. Reading and trying to understand the code is impossible. It would help though to see which Classes/Functions are called and then read/understand them.

So, is there any tool to log/record Http Request/Responses and what call graph of the php app it triggered? Preferably something that would not have to get written into the code?
I ditched PHP years ago and am somewhat rusty with my PHP Utility and Standard Library Toolset to know of something that could help me here.

Best Answer

So, is there any tool to log/record Http Request/Responses and what call graph of the php app it triggered? Preferably something that would not have to get written into the code?

The code coverage analysis functionality of xdebug will help you get a sense of what gets executed on each request:

Code coverage tells you which lines of script (or set of scripts) have been executed during a request. With this information you can for example find out how good your unit tests are.

xdebug's profiler outputs profiling information in the form of a Cachegrind compatible file, so in theory you don't have to do a lot in code, as you can configure xdebug via php.ini and htaccess.


This is the practical approach, don't stop here, you should follow the advice given by ChrisF and Morons.

Related Topic