Remote Debugging and Memory Profiling in PHP - php

Two Questions
How can I debug PHP code remotely which is lying on the server, currently I am using var_dump's to check the value of variables ?
How can I see how much memory and how much time particular function is taking to execute remotely which is lying on the server, any suggestion for good profiler for this ?
Note: I am talking about code which is lying remotely on the Server.

Like others said, Xdebug is your best bet. I'll just chime in here and mention a couple profilers. If you're on Linux you can't go wrong with KCacheGrind and on Windows it appears WinCacheGrind is what you'd use. I was not aware of remote profiling being an option, it dumps to a file which you'd need to have access to. Although, it appears you are accustomed to that already.
Komodo is a pretty nice IDE with Xdebug support (debug requires paid version), although there is no reason to not just install Eclipse and pick up the Zend PDT.
My suggestion, program in Python and be a happier developer (more developer-friendly modules/tools) :P

I think Xdebug is what you're looking for. If you don't mind spending the money, Zend IDE for Eclipse comes with Zend Debugger and it works quite well also.

As bender said: XHProf [1]: http://pecl.php.net/package/xhprof [2]: http://mirror.facebook.net/facebook/xhprof/doc.html is much lighter then XDebug and I prefer it for taking profiling info about the live site. Facebook uses it for profiling their live servers. It has nice features like aggregating the profiles and making diffs between them so you can see the regression in your code as well. If you need step by step debugger then XDebug is your call. Just be aware that XDebug on live site turned on by default imposes important degradation of performance, and output cachegrind files that site generate could fill the disk very fast.
I suggest not using XDebug on live site and if needed configuring it to activate on demand through trigger as described in docs http://xdebug.org/docs/

Configure your server to allow XDebug remote debugging and pick a client, although it can be a bit involved to set it up. I've personally used Geben for emacs as a front end for XDebug, but there are many choices.

As far as you're allowed to install stuff on the server Xdebug is the way to go for both debugging and profiling.
If you are on a shared server forget about it (unless you are a good friend of the server admin). Your best chance seems to be FirePHP - for debugging only. You may want to take a look at dBug too; it's basically a prettied up var_dump, but your eyes will be grateful for it.

Related

Conceptual Questions re debugging PHP web application in Eclipse

I'd like to debug a web application written in PHP in Eclipse but I have two questions that I need to get answered before I can hope to proceed.
First, how do I choose between the Zend debugger and Xdebug? I have no idea what the difference between them is.
Second, I am not remotely clear on WHERE the debugging takes place. I can picture any of these approaches working:
The debugging takes place entirely within Eclipse.
The code runs in a local environment like XAMPP.
The code runs on a remote server.
Frankly, I'd prefer the first of those alternatives for sheer convenience and simplicity. Is that realistic? My second choice would be to test on the remote server but, given that it is space on a free hosting service, I can imagine that the hosting company might not let me install the various facilities that would be necessary for debugging to work.

Slow PHP script - automatic debug and diagnosis?

How can I find out whether a PHP script goes bad and runs really slow when ran by hundreds of users every second, and better yet, is there any tool that could tell me approximately which part of the code slows me down?
...
I don't wish to post the code here (mainly because this question refers to something else and because it's a waste of space) and preferably never post it anywhere because it's actually a mess!... a mess that I understand and yes, i coded it, but still a mess which would insult anyone trying to comprehend it... so if you have any creative ideas, please let me know!
Cheers!
( thank you already for your incoming answers! )
Enable XDebug profiling, and send the resulting files through WinCacheGrind (Windows) or KCacheGrind (Linux).
This will allow you to see a breakdown of which functions get called most, and where the time is spent. Learning to use XDebug is a must for any serious PHP developer.
Here is a seemingly good tutorial on getting started with XDebug profiling.
You will need two tools
a profiler (Google it)
i use this one at work :
http://www.nusphere.com/products/php_profiler.htm (commercial)
a load tester
check this site for more info :
http://performance-testing.org/content/performance-testing-tools
I'd recommend to use a PHP profiler. Xdebug which is both PHP debugger and profiler can help a lot. There are also other debuggers, e.g. Zend Debugger.
To analyze profiling results you could also need a special tool. I used WinCacheGrind in Windows and KCachegrind in Linux.
Profiling report shows tons of useful information e.g. which lines of the source code were called how many times and which functions took the most of the execution time.

Step by step guide for benchmarking PHP project

Can anyone guide me how to load test/benchmark a project written in plain procedural PHP (no framework) and MySQL to identify the bottleneck ?
The project uses SESSION to store some values.
I've the last version of WAMP !
[On SO i found JMeter to do the job, but there was no step by step guide, neither i found it on the JMeter's site. Looking for help from you.]
If you want to profile your code to find out, which part of it takes all the time, you're looking for a profiler.
With WAMP, I'd recommend the xdebug profiler with webgrind to visualilze the data.
On the other hand, if you want to know, how much your site can take, you should take a look at Apachebench, which should come with WAMP.
You didn't specify, how complex your benchmarking needs are, but apachebench should make it possible.
Use PHPUnit for testing:
http://jsdoodnauth.wordpress.com/2008/11/05/installing-wamp-and-phpunit-on-windows/
Unit Test based development.
This allows you to produce bug free code. It also benchmarks for time.
And PHPUnit definitely is the way to go

Tool to profile php code

Looking for some [freeware/opensource] tool in order to make it easy to profile a big php project on win32 platform. Need to find out which part of code is most time consuming.
It's hard to manually put timing function for each function, loop...
You'll want to install and configure Xdebug. It's sort of the de-facto standard PHP debugging and profiling tool.
WinCacheGrind can crunch the profiling output. It's a bit buggy, but it does the job.
xdebug works quite well http://xdebug.org
Also wincachegrind is a good tool for looking through the profiler's output. http://sourceforge.net/projects/wincachegrind/
As well as (if the profile file is small) webgrind http://code.google.com/p/webgrind/
In addition to the excellent xdebug (as mentioned by others), you can also look at xhprof.
Yes, use XDebug, and once you're in it, use this technique, which works on any platform.
Don't think of it as measuring time.
Think of it as trying to ask, predominantly, What is it doing, and Why is it doing it?

How to debug a PHP application?

Which is the best way to debug an PHP application as we can debug ASP.NET application with Visual Studio ?
I'm using the IDE Eclipse PDT, which can use the PHP extension Xdebug to provide debugging functionnalities, kind of the same way as Visual Studio (a bit less powerful, maybe), which gives you the ability to do things like :
step by step
step in / out of functions / methods
see the content of variables
have a stack trace showing where you are
That's really nice to debug big programs -- especially ones you didn't write, to understand how they work (or don't ^^ )
It can also use the extension "zend debugger" ; but I've never tried this one.
Even without using a debugger like the one provided by PDT, Xdebug is a nice extension to have on a development server : it gives nice stack traces when there's an error/exception, it allows you to get nice-looking var_dump's output, ...
It can also be used to get profiling data, which you can visualize with tools like KCacheGrind, WinCacheGrind, or Webgrind.
But note it is hurting performance badly, so it definitly should not be installed on a production server !
PHP Console is good if you want to debug WEB 2.0 (AJAX) web-projects.
PHPEd is great for this, but you have to pay for it.
xdebug works, but you have to install it on the server. I haven't used it, but it seems to have a good reputation.
Some IDEs (Aptana/Eclipse + PHP springs to mind) then can interface with xdebug.
XDebug with Eclipse PDT is the best I've seen. Here is a tutorial on setting this up:
http://devzone.zend.com/article/2930-Debugging-PHP-applications-with-xdebug
NetBeans also has debug capabilities. From the website:
You can debug scripts and web pages, either locally or remotely. The NetBeans PHP debugger integration allows you to map server paths to local paths to enable remote debugging.
I use the Zend debugger and after trouble getting it working (it was a remote setup with he server and the development machine both virtual!) - it made a huge difference to my development efficiency. If you are converting from Visual Studio you will find quite a few things different and even difficult. It is worth sticking with it and mastering howewever - I can now set breakpoints in arbitary pages and navigate to them just like the user, stop and examine locals etc and then step through what happens - put simply now I can find bugs whereas without it I was guessing. Also see Developing with PHP and Eclipse (Galileo) which I found helpful.
PHP storm is a good one from JetBrains.

Categories