Step by step guide for benchmarking PHP project - php

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

Related

What can delay "Time to First byte" by almost 2s?

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

Best way to debug my way through a newly acquainted large PHP app and detect dead code?

Today I am faced with a spaghetti of some new unknown code for a webservice, and I need to make sense of it. The code is using CodeIgniter with a HMVC extension which helps, but the problem is that it contains many unused/old/etc... files/folders. It also does not help that I recently converted to using PHP, so I am still learning my way around best practices.
Is there a way to set the debugger up in a way that it breaks at the beginning of every single PHP file? (I have Xdebug set up ready to rock)
What is the most effective way to analyse code for unused files? ( I saw a few projects for this, but unsure where to start)
Thanks!
As per the discussion in the comments, I'd wondered if the execution coverage tools in XDebug would help here. This is a low-level code monitor that watches what lines of PHP code have been executed when you start a program. As you'd expect, this adds a certain level of overhead, so it is generally not added to live environments.
Hosted build systems like Travis and Scrutinizer do code coverage reporting, though they probably rely on tools like PHPUnit and XDebug to actually make them work.

How to build a complete, cross-platform and full automated test-suite for PHP/Ajax applications?

I'm trying to build a full test suite for Joomla and others. There are some docs around but they're quite limited and I'm wondering somebody did wrote already some scripts. By 'full' I do mean really a complete testing :
1. installing an extension on Windows, Max, Linux (Vagrant, VM)
2. configuring the extensions with the CMS option panels
3. doing things in a full Ajax application
I guess I'll end up with lots of bash-scripts, triggering other scripts within a virtual setup, right ?
I must admit, I am not really familiar with all this testing frameworks and products and I'd be already very happy to get pointed to anything. Doing pure unit tests doesn't seem enough given the nature of such systems (namespace collision, interfering plugins,...)
Thank you for any hints
I am not familiar with wordpress and joomla but those are just PHP code, so using PHPUnit can be suitable. With PHPUnit you are not only doing unit testing but you can also do other kinds of tests (it depends on how much time you are willing to spend on testing but I would say that it can cover pretty much any aspects)
As for front-end testing, there are several choices
Using selenium to write tests
Using one of the many headless testing frameworks out there (for instance, casperjs in Javascript, Watir for Ruby etc...)
For setting up virtual environment, apart from vagrant you can check docker
There are many programs you can use to do the normal interaction tests; if you want to handle logins, some scripting will be necessary to grab the token.
But for a full integration test including ajax I guess you'd be better off with a headless browser, take a look at this Real headless browser where the same requirement is discussed in detail

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.

Remote Debugging and Memory Profiling in 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.

Categories