Posts Tagged ‘programming’

Yay another project!

Sunday, June 15th, 2008

I just posted a blog entry about the open source Twitter client I’ve been working on. It’s over at Buttered Cat Blog. Hopefully some help will start trickling in.

Looking for a new name for it instead of TweetTweet, what do you all say about Tweetldum? Seems to be the liked one so far.

PHP Database APIs MySQL Edition

Thursday, May 31st, 2007

So I decided to do a simple performance test after a friend linked me to this blog post of someone doing a comparison against a PostgreSQL database. I use MySQL at work so I wondered if there was much difference with the mysql drivers for these various APIs. The results actually seem to show PDO to be the winner when querying a MySQL database.

Here’s the results:

Method Time (ms)
PDO Prepared: 0.01632
PDO Query: 0.01809
MySQL Query: 0.11709
MySQLi: 0.17366
ADOdb: 0.52558
Zend_Db: 0.74503
PEAR::DB: 1.21966
MDB2: 1.31814

This test was run on a Ubuntu PC, an AMD 1800+ (1.53Ghz) PHP 5.2.2 machine. A simple query was run 250 times returned about 270 rows, similar to the blog post I mentioned. The 250 query iterations were also run 10 times per API and the average of that is taken. The results fluctuate a little but are usually pretty close to the same. So it seems like for MySQL PDO does a pretty good job.

Edit: Added Zend_Db results, which uses PDO behind the scenes

Technorati Tags: , , , ,

Zend Core First Impression

Thursday, May 17th, 2007

So Zend Core recently released an update which has the PDO extension so I can now use it since all my applications run off of PDO for data access. Problem is I’m trying this on Mac OS X which currently has a problem with building PDO separately for PHP. So I had to wait for Zend Core to integrate the core PDO extension to even use it.

Zend Core offers a simple installation and management suite for a PHP installation. It installs PHP and it’s components along with some optional components (like phpMyAdmin and the likes and even Apache 2) and gives you a web interface for managing your php configuration, seeing general status of Apache, benchmark (ap), and grab updates automatically or manually for Zend Core. It’s also free to use it seems, you pay if you want support.

My favorite part of this is probably the offline searchable PHP manual it also includes and the easy to use php.ini editor that lets you edit settings & load extensions easily. Check out some screenshots.




Technorati Tags:
, , ,

Script Logger: Poor man’s Zend Platform

Thursday, November 30th, 2006

So I just recently updated my Script Logger app, a small PHP web app meant to drop in and log various errors and warnings generated by a larger PHP web application, including pages that might take too long. This was made in response to liking the ability to see what problems may have occurred on a server via Zend Platform that I tried out. So I decided to make a simple one using PHP’s functions for setting error and exception handlers. This isn’t the perfect solution compared to Zend Platform since it’s done with PHP code, and with the handlers, they can’t catch fatal errors. Maybe some day someone, or me if I ever learned how, could write a simple extension for catching all the various errors including the ones unable to be caught within PHP for logging. I’m thinking Xdebug is a good resource for this since it catches all the errors etc, and it would be a good companion to someone with a Xdebug PHP setup to have a free Zend Platform like alternative.

My Script Logger requires PHP 5.1 or better, the PDO extension to be installed (which it often is by default, at least if you build PHP), and sqlite2 or sqlite driver for PDO installed. You can possibly install these via pear/pecl too if you don’t already have them. To install just drop it on your web site, edit config.php to see if the error settings are to your liking, make db folder writable, and you should be good to go.

Script Logger

Technorati Tags: , , , ,

Zend Studio Decline?

Monday, November 13th, 2006

I’m starting to wonder what the future of Zend Studio is due to disappointing updates and the new PHP IDE Project backed by Zend. I’m quite disappointed that the java based cross-platform application that is Zend Studio isn’t a native application to OS X Intel. Supposedly this should work through rosetta, but come on, it’s java, it shouldn’t have to be specific to PowerPC, and shouldn’t be hard to fix this at least for the primary program. I believe my first attempt to actually install Zend Studio on my MacBook Pro was met in similar failure to the friend that warned me that it has issues on OS X intel. I seemed to have installed 5.5 beta just fine and it so far seems fine. But it’s still severly limited since you can’t use the Zend Debugger, Profiler, or Platform features since that requires the Zend extensions which are PowerPC and you can run PowerPC applications but not load shared libraries like those into intel applications. So basically it’s not a 100% package on OS X intel.

The other issue is that I have an expired Zend Studio 5.1, meaning it’s still valid to use but no free updates, so $200 to get 5.2 or 5.5 when it’s out. And for what? Nothing special at all, there’s some cool stuff, like Zend Platform integration is actually something nicer in 5.5 compared to the initial stuff in 5.2. I’m not sure I like the subscription style upgrade program, it benefits you at times like when a huge release comes out like say if 6.0 was coming out when you still had the support/updates. Mine happened to expire before 5.2 or 5.5 so neither are free, I definitely said no to paying to renew and get 5.2 since there was barely anything at all new, and 5.5 isn’t much better either. Not worth it until maybe 6.0.

Also, is Zend Studio going to be continued or is the PHP IDE Project slated to eventually be Zend/PHP’s preferred IDE of choice. Doesn’t seem like it, but the fact that Zend is helping with what would be competition for Zend Studio seems kinda odd. That and the lack of intel support for Zend Studio and Zend Platform makes it kinda uncertain if it’s worth spending money for an upgrade, at least not until there’s a better looking update that provides something more worthwhile. In the meantime I’m seriously looking at Komodo Professional to see if it’s at all a better deal, specially with all the languages it’s capable of handling, including code suggestion for more than just PHP, but for other languages and also CSS and XSL too. The biggest concerns for that IDE so far are performance/snapiness and limited PHP code suggestion. I don’t know if PHP IDE Eclipse project will be good, at least not yet, but Eclipse has been incredibly slow on linux and OS X. We’ll see how things progress with it.

Technorati Tags: , , , , ,

wxDebug for PHP/Xdebug, almost on OS X

Friday, October 27th, 2006

So I recently ran across SitePoint Blogs ยป wxDebug when searching for information about what people use to read the cachegrind outputs from Xdebug profiling. This is promissing since it’s a start of a GUI that runs on anything Python/wx runs on which is almost everything, including OS X. I’d like something similar to KCacheGrind but that might be a while before something like that would be available on OS X, maybe if wxDebug gets developed further. So my attempts to run it on OS X failed at first, but that seemed to be due to the bundled python & wxPython in OS X are old. Upgrading to Python 2.5 and latest wxPython resulted in it running and processing files at the least.

Wxdebug-Almost

So processing a file doesn’t yield in much happening on screen, but hey, maybe it’s easy to resolve. At least it runs, and the analyzer seems ok so far. I’ll have to look into it further sometime.

Technorati Tags: , , , ,

Howto: Xdebug installation and setup

Tuesday, October 3rd, 2006

To install Xdebug, it’s easy if you’ve installed PHP extensions before, follows the basic 4 step procedure. Also we’ll need to download it, I’ve been using the latest 2.0 beta with no problems, you can visit the Xdebug site to get more information and download it.

First we have to run phpize, this builds the configure script and other make/configure related files tailored to your install of PHP, you’ll need your PHP install’s bin folder in path, typically this is for system installed PHP or custom installs in /usr/local. If you installed PHP via something like apt in debian or ubuntu, you’ll need a particular package, this should be ‘php5-dev’ which includes phpize and necessary files to build PHP extensions. Then we can run configure, make, then make install to install it. The basic installation commands:

$ cd xdebug-2.0.0beta6

$ phpize

$ ./configure

$ make

$ sudo make install

Now that we installed it, Xdebug requires some minimal php.ini setup, particularly a special way of loading the extension unlike normal ones. I basically want the debugger available when I need it, and for Xdebug to be using it’s stack traces for any notices/errors, and profiling to be only on when I want it. Below is what I have, for debugging support (which requires something like Komodo or Eclipse with Xdebug support) you’ll need to enter the address of the machine that will have a debugger, along with the port, and the username you’re on on that machine. So this setup, my laptop will do any debugging, and I’m always ‘jerome’ on any machine, which is what the debugger clients usually use to identify the ide/client. For profiling you’ll need to have a directory writable by the web server where the cachegrind formatted profiler dumps go which is the last option I have.

zend_extension= /usr/lib/php5/20051025/xdebug.so ;full path to xdebug extension, installed in your extensions folder

xdebug.remote_enable=1

xdebug.remote_handler=dbgp

xdebug.remote_mode=req

xdebug.remote_host=192.168.1.40

xdebug.remote_port=9001

xdebug.idekey=jerome

xdebug.profiler_enable = 0

xdebug.profiler_enable_trigger = 1

xdebug.profiler_output_dir = /storage/sites/profiler_files

For other options, you can consult www.xdebug.org for documentation on xdebug and it’s configuration, available functions, and more.

Now to use profiling, all you have to do is restart web server if you haven’t already after saving php.ini changes, and then any script you want profiled, just include XDEBUG_PROFILE=1 in GET or POST and this will cause profiling to be run and a cachegrind.out.##### type file to be generated in the path specified in php.ini. It’s best to rename the file to something usable after the script is done so you know what it is, and if you do the same script, it might try to write to that same file. These files are then best viewed in a program that knows cachegrind format, like KCacheGrind as seen in my previous post.

Technorati Tags: , , , ,

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: , ,

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: , , ,