I was wondering whether there is a tool available that one can use to debug their database and php applications. Equivalent of firebug or chrome developer extension for databases and php. (I would like to know whether some queries are executed or not exected)
Use xdebug or a similar extension to debug PHP, in addition to the traditional var_dump and similar techniques.
Turn on query logging to debug what your database does or doesn't do.
To debug individual query execution, have the database EXPLAIN the queries to you.
PhpEd is awesome! Can hardly get out of bed without it these days, lol
Related
I have a number of production cron scripts that have unclear dependencies. The crons may or may not depend on an Oracle database backend. I need a function call that I can include in a PHP script to determine if any query or statement was executed during the execution of the script.
Note that some of the crons may connect to the database without executing any statements at all. Thus, simply using get_included_files() or get_required_files() (to determine if the script that initializes the connection is included) is not sufficient.
The first things that comes to mind is to use Oracle auditing and the second is to write a wrapper around oci_execute() and do some logging in the application.
Unfortunately, there's no great automatic way to do this. You can't simply log for when your database is used, since you say you have a "very large, legacy code base". How would you know when you reached all of the code paths?
You'll have to apply a human approach. Look at the places that do call database functions, start disconnecting things, use some intuition about where to look next. In the end, disconnect and see what breaks... but have a plan for knowing where to look for broken things, based on your inspection of the code.
I had a similar problem awhile back, but with register_globals instead of database dependencies. You might find this question and its answers helpful: Finding PHP scripts that require register_globals
I have enabled a PHP profiler, well magento, but it is still a profiler.
This is the standard magento compiler that records all the processing including all db queries to create the page, from receiving the request.
I am testing with a the php built-in server hosted locally.
The results show pretty decent server response times, but on the chrome developer tools the Time to first byte is much higher. Why is this?
Take Note...the screenshots below of the timings are from the SAME REQUEST...CLEARLY
Profiler (www.mysite.com/index.php):
Developer tools (www.mysite.com/index.php):
Edit
I had written a bit bigger answer but then I realized that you are using the built-in PHP server. Honestly, you should give a real webserver a go. You might be chasing a problem that does not exist (although one can argue that there is something going on because it's not a normal situation - you might be encountering a PHP bug) ;)
Found the issue.
The profiler is not recording included libraries. In the magento/lib folder nothing is recorded even if you explicitly set it to profile.
It seems that we need to use an all-encompassing php profiler
I'm trying to track down issues with an application [modx] I have several of these sites [about 10] on my server & was wondering how I can see what php is doing.
Pages on these sites are extremely slow while the same sites in dev are fine as are other php applications on the server.
I tried using xdebug to get an idea of what php was doing while processing these pages & where the bottleneck was occurring, but it only appeared to want to do anything on an error [there are no errors being thrown]
Any suggestions on how to track this down?
[linux/Centos5/php5.2.?/apache2]
Xdebug and webgrind are a nice way to see where your bottel necks are...
Read XDEBUG_PROFILE and Webgrind
Set up the php.ini to have xdebug profile your code on every run or if a special param is passed, then setup webgrind to read from the same directory xdebug writes its profile dumps to.
Webgrind will show you what functions and set of functions require the most time, it breaks it down and makes it easy to find slow and/or inefficient code. (eg. your script is calling "PDOStatement->execute" 300 times on a fast query [Or calling it once and a massively slow one] taking up 90% of the execution time).
The most commonly used tool, for finding bottlenecks in PHP, would be Xdebug. But you should also manually examine the codebase.
There are three different areas where you will have to focus on:
frontend performance
SQL queries
php logic itself
.. and the impact on the perceived speed is in this order.
You should start by running ySlow, and make sure that your site follows the guidelines as closely as possible.
The next step would be tracking down what SQL queries are executed, and (assuming you are using mysql) try to run them with EXPLAIN. Also, check the queries themselves. There might be some extremely stupid code there, like ORDER BY RAND() or use of LIKE in huge tables.
And the last stage would fixing it all would a hard looks at the code itself. Both on PHP and JavaScript side of things.
Also , you should upgrade to PHP 5.3, because your version is extremely outdated.
Usually when you don't know what you're looking for, you cannot spot it with tools like xdebug or other plugins/debug bars etc built into CMS/Framework, new relic is the simplest solution - you'll be able to spot bottlenecks after few min.
while new relic is a paid app, you can test if for free for first 14 days - it's more than enough to find problem.
It's great because it integrates all other tool's and data sources you usually use:
xdebug, cpu & i/o monitoring, mysql slowlog, queries log.
It will also show you if your app is slow on php/DB/frontend/network.
You should try it out instead of wasting time for debugging with other tools.
here is a guide for centos installation: https://newrelic.com/docs/php/php-agent-installation-redhat-and-centos
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.
I have problems because i don't really know how I can test my code and sql ( mysql ) to see how long SQL queries and PHP functions /code take to run.
Does anyone here know where I can find these tools?
For PHP code, you can use xdebug for profiling. You'll need a frontend to read the trace data as well. If you're on windows, you can use WinCacheGrind. For other OS'es you can use either kCacheGrind (Lots of features, but a bit scary for beginners) or WebGrind (Much simpler and nicer looking).
For Mysql, you can use maatkit for profiling multiple queries, and to analyse a specific query, you should use EXPLAIN.
This is called profiling. XDebug, APD and probably some other packages provide this functionality.
The search keyword you want is "profiler".
There's several PHP profilers out there; XDebug, PHPEd Profiler, APD, DBG, and PQP, just to name a few.
I've used XDebug on several occasions and though it can be a little annoying to get up and running it does a pretty decent job. Just follow the installations docs and you should be fine.