Posts Tagged ‘PHP’

PHP Xdebug Profiling, pretty graphs!

Tuesday, October 3rd, 2006

So today I did some legitimate profiling of some PHP code using Xdebug for the first time. I used KCacheGrind to open the output files. I had a page in our mailing application that allows importing of emails from a csv file or an excel file, which was taking too long and eventually timing out when given a few thousand entries. I was able to profile a few times and improve code until it finally didn’t time out. The first thing was the importer class which implements the Iterator interface (from SPL), in which array_keys was called over and over again in the iterator functions, so had to store that in an instance variable and therefore much improved that area. Next up was the code responsible for putting the emails in the database, profiling showed that it was calling a settings class a lot, about 58% of the time it’s doing MasterSettings::find() call:

That’s obviously not good, easily fixed again with storing it in an instance variable so I have the limit setting I was asking for available instead of querying the settings system every time. Next profiling run showed addSubscriber and getSubscriber to be the two most time consuming operations, and what they were doing that was time consuming:


So the MSList addSubscriber function was calling subscriberCount() on itself a lot, and that was eating a lot of time. Turns out that was querying the database doing a COUNT() every single call, this being done nearly 6000 times in this particular case. Since ’subscribers’ are added and removed via functions, I changed the subscriberCount() function to only pull from database once and then from there, the add/remove functions increment/decrement respectively. That helped a lot but left the getSubscriber() function that calls to the database to see if one exists, otherwise creating an entry. This I tried to improve but realized not much can be done beyond usage of memcached in the database class. I basically cached the database results into a static class variable, which only served to improve performance when importing a list that has a lot of duplicates. This might be an excellent test case for trying memcached out.

After all that, I’m left with the main script file and getSubscriber() taking the most time up, and the script no longer times out, still some concerns about the database hit but the script is a lot quicker now, and Xdebug + KCacheGrind proved to be very valuable.

I highly recomend Xdebug on the awesome stack traces for notices/errors/warnings alone, I don’t know how many times that’s helped when getting a NOTICE from who knows where.

Technorati Tags: , ,

Experience with Xdebug and Komodo Pro

Wednesday, September 6th, 2006

So with the recent arrival of a MacBook Pro for work, I needed to setup my PHP development environment which usually consisted of Zend Studio, but that has YET to come out with a intel/universal release despite the fact that it’s 99% java. One of the useful things with Zend Studio is that you can debug and profile PHP sites with it, which I don’t actually use all that often, it’s still incredibly valuable. So Zend Studio may actually run fine on here through Rosetta, but word is, not very well and installer has major issues specially with latest version. What will not work at all is Zend Platform or Zend Studio Server, comprising of ZendOptimizer and what not, PHP extensions, which will not load into apache/php at all being PPC library files.

In comes Xdebug, an open source PHP debugging and profiling extension. It also totes a few nice features beyond that, like ability to give you stack traces for just about any error message, including notices and warnings. Installation of Xdebug was easy if you’re familiar with PHP extension compliation, plus if you’re trying out Komodo Pro also, it can install the extension for you and set it up. Xdebug is not too useful by itself, it’s best used with an IDE like Eclipse PHP IDE or Komodo, which allows you to view the PHP source file and step through it, set breakpoints, and see what variables contain what. This pretty much compares on-part with Zend Studio’s debugging abilities, with the added bonus of some other cool features.

The one thing I’d love to see be easier and as nice as in Zend Studio is the profiling of PHP code in Xdebug. This can be enabled and you can flag a page for profiling easily, what this does though is dump a file to a determined folder by the php.ini. This file is a cachegrind format file which can be viewed nicely in apps like KCacheGrind or WinCacheGrind. This would be cool and all if I weren’t on OS X. It doesn’t seem there’s any tool to view this data easily and nicely (specially as nice as a pie graph and such in Zend Studio) in OS X. This seems to be mostly due to the fact that these tools are all based around a tool called valgrind which is for linux and does not run on OS X that I can tell. What I did find after googling a bit is a perl script that will let me get some basic stats out of these files, ct_annotate.pl from the callgrind package. I found this after searching a bit on a mailing list as an attachment. My blog refuses to provide this file though.

I still haven’t had too much experience with Xdebug yet, but I’m impressed so far, just wishing for a visualization tool for cachegrind formatted data in OS X. I also tried Komodo Pro during this whole process, which seems like quite the powerful IDE. I was sparked to try this while looking into Xdebug, and not having any interesting in Eclipse, and running across someone in a similar boat over at Random Strings. This person, also a certified Zend Engineer, used to use Zend Studio but made the switch to Komodo Pro after purchasing a MacBook Pro. Seemed to be pretty positive, at least about debugging. My initial experience is pretty positive, seems to be quite powerful, the newest upcoming release has some nice features like CSS auto-complete, a HTTP inspector, and also ability to debug javascript via Firefox and an extension. I’m still going to give it a run through with my trial copy to get a good feel for it. My biggest problem so far is just that Zend Studio has an incredible auto-completion ability with it’s parsing of PHPdoc tags and being able to complete instance functions etc. Komodo Pro seems to be limited to class names and functions. I’ll probably use Zend Studio again on the MacBook Pro soon as it’s universal or available for intel, which Komodo Pro did very fast.

Check out some simple screenshots.
* Komodo Pro - Editing
* Komodo Pro - Debugging PHP page
* Simple profiling via ct_annotate.pl

Technorati Tags: , ,

Sad PHP Poem

Monday, June 26th, 2006

Just saw today on “Zend Developer Zone”:http://devzone.zend.com/node/view/id/576 a post talking about a “PHP poem”:http://jadmadi.net/2006/06/26/php-sad-poem/ that was kinda funny, at least for us geeks. Give it a read, it’s a little sad poem.
Apparently it was posted on the PHP general list originally so thought I’d provide the “link to the original”:http://marc.theaimsgroup.com/?l=php-general&m=115129593132595&w=2 . Although not entirely sure if he’s the author or not, but none-the-less, it’s a hoot.

Technorati Tags: , ,

MySQL Tool Review: phpMyAdmin

Tuesday, May 30th, 2006

One of the most popular MySQL management tools out there, phpMyAdmin has become widely used, but I’d have to say it’s one of my least favorites. I did use it back in the day and it wasn’t too bad, some of the features it offers are very useful. It’s one of the few tools to let you do things like rename a table simply, or other move-stuff-around type actions. My discontinued use of it started out with a particular update and there after performing horribly slow on my G3 server. I’m assuming this particular problem could possibly be gone now, but it made me ditch it quite fast. This could’ve easily been some other problem for all I know, but first reaction just was to ditch it and use CocoaMySQL instead at the time. I’ve never used it since partly because I got along fine with various other tools, and also my current employer does not use it due to security concerns. From phpMyAdmin being such a popular application, it’s prone to security holes way more frequently than other tools, mostly because of it being a public accessible tool for your MySQL database.

Shots of both phpMyAdmin themes/styles:

Overview of the ups and downs of phpMyAdmin:

Pros

  • Access from any machine, no installation of client software needed
  • Robust set of features
  • SQL file import and export with reasonable options
  • Table operations like renaming, moving data etc.
  • Simple tools for copying data or structure from database to database
  • Display of row data only limited to your browser ability to render that much html (or just use the pagination)
  • Full suite of tools covering querying to privleges

Cons

  • Uses frames for it’s interface, can be funky sometimes (would be better with no frames, ajax, even iframes maybe)
  • Font sizes of default themes bit wonky on latest one I tried, fixable of course (big on default, tiny on dark)
  • UI can be a bit sluggish due to it being a web application, depending on connection speeds etc.
  • Can be prone to security holes due to popularity, updates are usually quick though
  • Can’t do ‘quick edits’ like some desktop clients allow

The power and versatility of phpMyAdmin puts it at the top for MySQL client tools, but mostly out of personal preference I choose to remove it from my list of clients. The problems with phpMyAdmin are pretty slim, and if you don’t mind a web-based MySQL client, then you probably are already using this, or will at least find it suitable. So far I’m pretty convinced that a web-based MySQL management tool is just not something that will ever jive with me, I yearn for the snappier and cleaner UI of a desktop application when it comes to managing my MySQL databases. Unfortunately most of those bring in their own set of problems as seen in MySQL Query Browser Review and soon to come with reviews of YourSQL and CocoaMySQL.

Technorati Tags: , , , , ,

Modified TextMate PHP Bundle

Tuesday, May 23rd, 2006

I was having a improve-my-TextMate-experience moment and along with making some small snippets to help smooth my coding when using TextMate, I also went thru TextMate’s PHP bundle and applied my preferred formatting to all the snippets in it. It has formatting for conditionals like so:

if(conditional) {
// code
}
else {

}

and require/include sans () (like PEAR standards):

require_once ‘filename.php’;

and some other various cleanups like the random occurrence of # comments and extra tabs & spaces where they shouldn’t be, or at least I don’t think they should be.

So if you have similar coding style, check it out see if it’s an anal enough style for you or not.

“Download Jerome’s Anal PHP TMBundle”:http://jeremyknope.com/files/PHP-tmbundle.zip

Technorati Tags: , , ,

PHP Debugging Bookmarklet

Wednesday, May 10th, 2006

I just created a simple bookmarklet to invoke Zend Studio’s debugger from a browser with the page I’m currently viewing, I can even do this on a different machine if I have it setup to allow other hosts to do remote debugging. Here’s the code, you just have to replace debug_host= value with your Zend Studio machine’s IP. You can just drag this to your bar and edit it to match your setup or just copy the href.

Debug PHP

Install PHP with Extensions Howto

Monday, March 13th, 2006

I decided to write up a post about how to compile & install PHP with support for using extensions to provide all the functionality instead of building everything in. Compiling in everything seems to be pretty common, with the windows PHP install using extensions to enable anything like mysql, pdo, curl, and more.

These instructions will apply to linux or OS X, where OS X has one minor problem which is with “PDO”:http://www.php.net/pdo, therefore if your doing this on OS X, compile PHP with PDO + PDO drivers you need instead of trying to install them as separate extensions.

If you have any comments, thoughts, or questions, feel free to comment or email me(You gotta look for my email :-P ).

*Update:* Soooo apparently majority of the extensions fail to even try to compile on OS X, the makefile isn’t generated properly so nothing compiles so nothing can be installed. I had to build in curl, pdo, and xsl since they failed to build separately. These all worked in debian linux.

(more…)

Lightbox, super cool

Monday, February 27th, 2006

So I just implemented the usage of “Lightbox”:http://www.huddletogether.com/projects/lightbox/ on a work project since I wanted to make a full-image-viewer from clicking on thumbnails but did not want to have to go dig up the javascript for it etc. I then realized lightbox would be perfect since it’s usage on my blog. Lightbox isn’t anything new but it’s damn cool I must say. This just after being psyched about implementing “Ajax-powered drag & drop”:http://php.macsaresexy.com/sort/ on the same project, downside is the drag & drop doesn’t have a non-javascript method yet.

Zend Certified, officially framed!

Monday, February 13th, 2006

So I’m now definitely Zend Certified now that I got my framed certificate, seems kinda silly but kinda cool at the same time.

Check it out:

Dsc03202

Database migrations, ActiveRecord:Migration wannabe

Tuesday, January 24th, 2006

I just recently finished a ‘beta’ version of a ActiveRecord:Migration wannabe database schema migration system in PHP at work. It allows me to version the database schema/structure easily and allow for easy database structure updates when updating an install of a web app on some site. Eventually it could do downgrades like the rails version too but that’s not something I’ll worry about right away. It does function, isn’t as elegant as AR:Migration but it does the job which is pretty cool. It might join PHPFlash class as one of my most useful chunks of code.