Polls? Anyone???

Does anyone want to know what the (residing) KC PHP community thinks about some topic? Don’t be shy, request a new poll topic by commenting on this article. It’s quick and painless…and it can give you new insight into the minds of the other developers.

February Meeting – XML_Tree/RSS

When people ask me for a list of “why PHP” I often include in my response that it has All of the Buzzwords. Simply put, if there is a reasonable web-related standard out there, chances are that there is class or something to work with it in PHP. XML may or may not be a buzzword, but whithout question PHP does support it.

Learn more about working with RSS and other XML types in this month’s PUG! Read on for more

The problem may be that PHP supports XML processing in a bunch of different ways but only one (or maybe two) of them ship standard. This can make it tough when you don’t run your own server

Also, I won’t be covering schema’s or DTDs, you can find info on those at the w3c website. What I do want to show are ways to work with XML that don’t require any additional compiling or loads of work!

As usual, when I want to work on something new,I look at what is in pear first. There are a ton of places for other classes out there (like phpclasses.org) but there is also (quite often) a whole lot of junk out there too

PHP ships with the expat libraries enabled these days for parsing XML. While it works… well, let’s just take a trip to the onlne doc, shall we…

Notice that it is event (or call-back) based. That’s all well and good…and see how easy it is to manipulate start tags into something and end tags into something….Hmmm, isn’t that what XSLT is for? Anyway, I’m not even going to cover this. I’ve used it…it’s in a production system, actually…but I had to keep track of state in class variables, etc…it was not pretty. Maybe there are better ways to do this, but it does take practice to wrap your arms around it. If it works for you, go for it…it is the fastest and most efficient way to parse XML.

One of the many who know what they are doing, has written an RSS parser using the expat extensions. Perhaps more accuratly, using the Pear XML_Parser which helps you write event parsers in a class.

RSS – A very popular XML application

As I understand it, RSS is a small part of the Resource Description Framework (RDF). Put simply, it is a way for sites to publish meta-data about their content for other applications (and sites) to use. While this has not cough on with many of the big sites, for fear of loss of revenue (cough, cough) or whatever…there are plenty of RSS feeds out there on the web.

First, let’s look at a simple RSS feed in the docs for XML_RSS.

Let’s start actually working through some other examples:

  • Here is a goofy little function to (poorly) draw out an html representation of the feed. Source: rss.php
  • And a little program to drive it. Source:simple.php
  • And finally, what we get when we run simple.php
  • What about other types of XML?

    Of course, working with a canned standard and a canned class is one thing, but what if we need to work with our own xml layouts?

    Just for the sake of example, we are going to write our own XML application. That’s application in the XML sense of the word. We are going to make up our own file format to hold the “feeds” array.

    Of course, we will take it a bit farther though, as XML is just so darn flexible

    So, let’s start with our Example XML file.

    First off, notice that we have kept the concept of “feeds”. These are just “groups” of RSS links. Notice, that we have even sprinkled some formatting data into our XML. This is generally BAD, but I’m just trying to give examples.

    Now, we are going to keep the same drawFeed() function that we used before…but we do want to try to swank it up a little, right? Also, we are going to use the pear library XML_Tree. This was written with the intention of creating an object-oriented XML writer for php. However, the author added the ability to read in an existing document and viola.

  • Take a look at the new code: Source: better.php
  • As well as the Output of better.php.
  • The new formatting (aka pretty stuff) is all handled by a few lines in the style.css.
  • For an easy listing of the demo files, just go to the doghouse

    Keep in mind, the XML_Tree library can be used for outputting XML in a clean (sorta) OO kind of way. Check out the docs for XML_Tree for more details.

    Happy PHPing!
    Dan Holmes

    PHP CLI Ncurses

    Link: Using Ncurses in PHP

    PHP Command Line Interface has made some vast improvements over the past few months. One of which is Ncurses functionality. I read this article at Zend.com and thought it was very cool. It allows you to format the text on the screen. The article has screenshots to help you understand what it really does.

    Before everyone tackles me for using PHP for shell scripts, I’d like to present my reasoning. Sure, even with the advances PHP has made recently, PERL is still probably a better option for shell scripting. Quite frankly, I don’t have the time to learn all the ins and outs of PERL just to write a simple script to dump some database records. I already know how to do that in PHP, so why not use PHP? I think sometimes people underestimate the value of having one language that can do everything you need. It keeps syntax confusion to a minimum and allows me to study the more advanced aspects of the language instead of just knowing the basics of multiple languages. Not to mention it cuts development time by ungodly margins.

    I urge you to give PHP a try for shell scripts (That is, unless you are already a PERL god, which I am not).

    January Meeting

    With the new year comes a new website, assorted info, and a way to speed up your use of frameworks. All inside this month’s PUG

    New year, new site: Powered by GeekLog

    I introduced the new PUG site…now powered by the geeklog site-in-a-can solution. I wanted to discuss some of it’s internals, available modules, etc…but instead just rambled a bit. 😉 There is already an intro article out there, so read that for more info if interested. After the meeting, Doug pointed out that codingtheweb.com has a portal-portal with RSS/RDF feeds. And, oh yes…they have a PHP feed (which I think is just stuff with the letters PHP in them). I added the RDF Portal box to the PUG site. Enjoy!

    Everyone is invited to write articles/comments/etc for our PUG…you can even submit one anonymously!

    Other Topics

    We had a general Q/A section and discussed things such as our favorite editors (VIM, komodo, ftpedit, and dreamweaver MX to name a few), some of PHP 4.3’s new features, using GD and ionCube’s PHPAccelerator.

    Image_Transform

    In answering a question, I introduced Image_Transform…a PEAR class for abstracting various image manipulation libraries. I have used it to scale images down on the fly but without the headaches involved with different GD versions or pixel math manipulation.

    This abstract factory style library provides member functions such as: resize, scale, scale to a max height/width, add Text and others. Having this in an abstraction layer allows you to switch libraries out depending on what is available on you system or based on what performs the best for your needs.

    For example, I had always assumed that GD’s imageCopyResampled would be the fastest way to size images on the fly. As it turns out, I actually got better performance letting Image_Transform use the mageMagik command line utilities.

    The ionCube PHP Accelerator

    We all know that PHP is bashed by “other” developers because a PHP script is usually compiled every time before it is run. When using single scripts or even small libraries, this compilation takes so little time it goes unnoticed. However, as you site grows, frameworks are implemented and your compile times start getting up there into the .5-.8 second range…you might start thinking that you need to invest in more hardware. This just usually isn’t the case.

    Sometimes, all you really need is something that will cache that compiled byte code. There are several alternatives available, such as the ones from Zend. However, as money is sometimes hard to find we have to go in search of other solutions. Enter ionCube and their PHP Accelerator

    There are some restrictions: It requires PHP 4.0.6 or higher (and you should too) and Apache 1.x in *nix, but if that is your setup…then enjoy!

    It also may not play with other Zend/PHP modules. For instance, the Komodo debugger did not work when I used it in the same server as PHPA. No big….I doubt that you will want to use it on a dev machine anyway as it can lead to a little “weirdness”. For instance, say you had an abstract class called Fruit and it is in a file called fruit.inc. Then you have a class called Apple which includes fruit.inc and extends Fruit. Now, all is good and the cache works great. Until, say, you add a member function to your base class: Fruit. PHPA will notice that THAT file has changed, and will recompile it. However, the functionality will not propagate down to the Apple class. Apple will still be the compiled version from before the functionality was added to it’s parent.

    If this doesn’t make sence…then you probably won’t have a problem with it anyway. 😉

    While I didn’t bother to write down exact numbers, when I was implementing this for our framework I noticed response times (from start of request to page render, using the advanced “time lynx -dump www.yourwebsite.com” command) were easily cut in half. Of course, I have written a fairly sloppy framework built on top of another big framework…but hey…like I said: in half. 😉

    Behind the scenes it uses apache shared memory segments and a directory on your filesystem to efficiently cache your PHP byte code. If your code wants a pick-me-up…this might be an afternoon alternative to a major rewriting effort.

    Happy Coding! And see you next month!

    All menu-based sites covered by SBC patents?

    Interesting legal case, as [url=http://www.sbc.com]SBC[/url] (we should DOS them) claims that they have the [url=http://www.theregister.co.uk/content/6/28985.html]patent rights[/url] to any frame or menu based navigational system. Appearantly, they are requesting [url=http://www2.museumtour.com/sbc.html]royalty fees of 2%[/url] of total revenue of any site that uses such navigation methods.

    Not happy with the street smarts of their legal counsel. When will they learn?

    a little byte is a lot

    Nice up on the Geekware!! I’ve been looking for a good one and other blogs like Thatware, PHPSlash, Nukes (I agree, they don’t deserve links), PHPWidgets (still shows potential), and even grandaddy PERL Slashcode. After all this, I show up to the PUG for the first time and BAM, Geeklog, what I’ve been looking for, right in front of me. Definitely glad I came. I will be pushing a few blogs in the next couple of months, good to see something with some flexibility.

    Also, have some suggestions/requests/ideas/whatever, probably post when the weekend hits. Brain is fried in middle of week.

    Again, Nice up on the Geekware!

    Welcome to our new Site!

    It was a LONG time coming, but with little fan-fare and much rejoicing (mostly from from myself)…I bring to you the new KC PHP UserGroup website. Read on for more.

    There is much to do, but I wanted to bring up something before tomorrow’s meeting. I wanted a site that belongs to all of us where anyone could submit an article. Of course, there will be an approval step…but I’m hoping that maybe this will become what I had hoped the Discussion Boards would.

    I was also really tired of using an ancient version of the content management system that I am writing for my place of employment. The thing has come a long away…but it is just not what I wanted for this site.

    I wanted fast content addition, polls, article/event/url submission, extendibility and maybe a photo album

    Oh, and for personal reasons, it could not be PostNuke 😉

    So, I stumbled into Geeklog, and I am happy.

    I’m sure it will take me a little while to move the content and get all settled in…but I like what I see, and can’t wait to see what this baby can do for us.

    If you have comments, feel free to add your voice here or on the Poll.

    See you at the PUG!