Christian WeiskeUploading diff files with Opera (27.8.2008, 11:15 UTC)

The web interface to the PEAR bug tracker allows us to upload .patch and .diff files. It checks for the Content-type of the uploaded file and rejects everything that's not a text file.

I tried uploading my patches many times and always got rejected - when using my beloved Opera browser. It worked with Firefox and Konqueror, though. Yesterday I finally took the time to find out why this happened. Started up my favorite network traffic sniffing tool, Wireshark, and uploaded a patch.

The second HTTP POST packet told me why I got rejected: Opera sends the file with type application/octet-stream, apparently because it does not use my system's MIME database and doesn't contain the information about diff files itself. So I opened Preferences, Advanced, Downloads and added a new MIME type text/x-diff for .diff files - and uploading patches to pearbug works like a charm.

Link
Ken GuestIs PHP vulnerable software? (26.8.2008, 13:15 UTC)
Thanks to Ivo Jansch, I spotted Matt Assay mentioning in his article on cnet that PHP headlines in IBM's list of most vulnerable software and I have to say this is complete balderdash on the part of IBM. He quotes from the report: Another commonality between these three vendors is that they ...
Link
Christian WeiskeImporting huge XML files using PHP5 - efficiently and conveniently (23.8.2008, 22:15 UTC)

At work I had the task to implement the synchronization between an online shop and a commodity management system. Data exchange format was XML - one big XML file for all of the products (some thousands with dozens of attributes). Big question: How do I import the file in a way that is most convenient for me as a programmer - and without exceeding the machine's RAM when loading a 1 GiB file?

I personally prefer SimpleXML for everything XML related in PHP - even to generate XML; although it was never meant to do that primarily. The big problem is that SimpleXML uses DOM in the background which builds the whole XML tree in memory. That's a no-go for large files.

So what's left? Yes, our old and rusty Sax parser. It's not really convenient - you have to catch all this actions for open tags, close tag, data section etc. - but it reads the xml file iteratively. Parsing huge files is no problem if you use Sax. PHP5's slightly enhanced Sax implementation/wrapper is XmlReader which I chose to make use of.

On the other side - my program that synched the data with the database - I wanted to have something dead simple, like a foreach loop. Now the task was to combine XmlReader and SPL's Iterator interface.

Sample XML

<?xml version="1.0" encoding="utf-8"??>KateLGPL
EditorNice KDE text editor
3.5.94.0.5
geditLGPL
EditorStandard gnome text editor
2.22.32.22.4-rc1

Preferred PHP import code

The following code is as easy and beautiful as reading an XML file can get:

$it = new ProgramIterator('programs.xml');
foreach ($it as $arProgram) {
    echo $arProgram['name'] . "\n";
    echo ' Latest stable version: ' . $arProgram['version-stable'] . "\n";
    //here you could do some db operations
}

Iterator code

Here is the iteration code - without comments - in case you (or /me) need to do the same thing again.

class ProgramIterator implements Iterator
{
    /**
     * XML file path
     *
     * @var string
     */
    protected $strFile = null;

    /**
     * XML reader object
     *
     * @var XMLReader
     */
    protected $reader = null;

    /**
     * Current program
     *
     * @var array
     */
    protected $program = null;

    /**
     * Dummy-key for iteration.
     * Has no real value except maybe act as a counter
     *
     * @var integer
     */
    protected $nKey = null;

    protected $strObjectTagname = 'program';



    function __construct($strFile)
    {
        $this->strFile = $strFile;
    }

    public function current() {
        return $this->program;
    }

    public function key() {
        return $this->nKey;
    }

    public function next() {
        $this->program = null;
    }

    public function rewind() {
        $this->reader = new XMLReader();
        $this->reader->open($this->strFile);
        $this->program = null;
        $this->nKey    = null;
    }

    public function valid() {
        if ($this->program === null) {
            $this->loadNext();
        }

        return $this->program !== null;
    }

    /**
     * Loads the next program
     *
     * @return void
     */
    protected function loadNext()
    {
        $nCount = 0;
        $strElementName = null;
        $bCaptureValues = false;
        $arValues       = array();
        $arNesting      = array();

        while ($this->reader->read()) {
            switch ($this->reader->nodeType) {
                case XMLReader::ELEMENT:
                    $strElementName = $this->reader->name;
                    if ($bCaptureValues) {
                        $arNesting[] = $strElementName;
                        $arValues[implode('-', $arNesting)] = null;
                    }
                    if ($strElementName == $this->strObjectTagname) {
                        $bCaptureValues = true;
                    }
                    break;

                case XMLReader::TEXT:
                    if ($bCaptureValues) {
                        $arValues[implode('-', $arNesting)] = $this->reader->value;
                    }
                    break;

                case XMLReader::END_ELEMENT:
                    if ($this->reader->name == $this->strObjectTagname) {
                        $this->program = $arValues;
                        ++$this->nKey;
                        br

Truncated by Planet PEAR, read more at the original (another 539 bytes)

Link
Ken GuestIrish PHP User Group: Committee Forming (20.8.2008, 23:15 UTC)
Yesterday. a few weeks after much discussion and evolution of the constitution of the Irish PHP Users' Group I suggested that we should get our skates on and get to forming a committee. Nominations were made today for all of the posts but there's a week left before the results are ...
Link
The Nazg SpeakethNext Bug Triage Days for PEAR (20.8.2008, 15:15 UTC)
Link
Lukas Kahwe SmithOpen Source is not making enough rich people richer (18.8.2008, 17:38 UTC)

I keep seeing this posts by some of the manager types on planet MySQL about how they or some other guy is worrying about open source vendors not raking in billions or are not stealing billions of money out of peoples pockets that should not be playing on the stock market and things along those lines. While I do agree that its great to see open source software flourish .. actually let me clear that up, why do I even care if open source software flourishes? I care because I think open source software enables a different kind of growth for society, one that is shared, one that lowers barriers, one that I feel is more in tune with a world at peace.

Of course I want people that take part in this to be able to provide themselves and their families a decent life. But the fact of the matter is, these people do not need millions, the people that use this open source as an enabler do not need millions in marketing budgets either to realize the usefulness. Of course market capital can help in funding boring tasks like QA and documentation or full time developers etc. But the show will go on even without that.

And guess what? Those small companies that make a buck with open source, they foster a culture where people go home happy at the end of the day instead of being bitter like most others. This is of course not something easily valued in monetary terms, but its nice that the pool of would be homocidal maniacs is reduced by these companies. At the same time even big guys are making plenty of money and giving back a bit here and there. New companies are popping up and slowly making it to big bucks too. So whats the point of this blog post? Lets get over this obsession with these companies that are supposed to make a few people insanly rich by selling their life (aka modern slaves) to VCs that are owned by people that haven't figured out yet to do better things in their lifes but to stack their millions higher and higher.

Reminds me about the irritation I see these aquisition rumors: Of course it matters to people who their are getting gobbled up by and so its not trivial that a Microsoft goes knocking at the doors of Yahoo (not that Yahoo is a small shop or entirely dependent on open source, but from the outside it seems none the less sufficiently open sourcy for a fair share of the tech staff). Do they really believe that key people will stick around after they are required to use their new "@microsoft.com" email address? Especially since these key people have plenty of options. Then again I guess these guys know their risk-analysis 101 and they are mostly after buying users.

While I am trying to save the world, I might also want to mention that its time we kick the system a serious jolt. I like standards, but the out dated processes by ISO and the likes are making a mockery if the idea. Seems like a little less corruption in such public services is too much to ask. Anyways, lets end this post not well formed </rant>

Link
Greg BeaverMacbook Pro lives up to expectations (14.8.2008, 22:35 UTC)

Well, it's been a long and practically empty summer for me in terms of coding, what with hardly any internet access and even less time.  I did manage to have time to improve the scheduling program I wrote for Greenwood Music Camp where we are in residence, but that was it.

Now, a new leaf has been turned over.  The Chiara Quartet has a residency at the University of Nebraska-Lincoln that began in 2005 for a 3-year term.  Much to our delight, the residency was renewed for another three years, and converted into a permanent residency.  None of this has much to do with programming, but a perk of this job is that every 3 years, we get a new computer to replace the old one.  This cycle, I requested a Macbook Pro, my first Mac, as I have been using a PC for years.

I had the tech peoples set up VMWare Fusion for me, and so I am currently running Mac OS X, Ubuntu Linux, and Windows XP simultaneously with noticeable performance gain over any previous computer I have owned, including my custom 64-bit Kubuntu desktop.  The screen is beautiful (15 inch Matte) and speakers far superior to other Macs I've heard as well as the Toshiba laptop I will soon return.  I was able to very quickly set up a working PHP 5.3 with xdebug and Komodo in Mac and linux, and almost have the windows side compilation of PHP working, which will greatly accelerate my development.  The ability to share changes with the shared folders between all 3 boxes will be a tremendous boon to my development, this will be fantastic.

It feels good to drop Windows as the native platform too, it's been a long time coming.

Link
HelgiPEAR installer updating its PHP deps (11.8.2008, 09:18 UTC)

So the title says it all, kinda ...

For the next alpha release of PEAR that will happen in 2 - 4 weeks we'll have a min dep of PHP 4.4 and 5.1.6, so basically excluding 5.0.0 - 5.1.5 Now why am I going to do that ?

As any decent PHP developer know, PHP 4 is dead so to at least stay in the latest PHP 4 release I decided it wouldn't be worth the hassle to maintain support for 4.3 anymore (It's also the case with PHP 4.4 but I kinda dislike abandoning people altogether) and well 5.0 nobody uses except for crazy people and everyone in the 5.1 series should be up to 5.1.6 anyway since RHEL uses that and most of the LTS distros out there.

So yeah I'm doing this so I don't have to test on so many PHP versions as well as hopefully nudge users to upgrade their PHP if they wish to use PEAR anymore ... kinda ... a little known secret is that the installer still works fine on 4.3 and 5.0 - 5,1.5, you just need to do pear upgrade -f pear if you want to keep on using those old ugly PHP versions but be warned, I'll bogus any reports that has those numbers and I can't properly reproduce any of the newer versions of PHP.

Now some people might be wondering things like: why didn't you put PHP 5+ dep and rewrite the damn installer to proper PHP bla bla bla bla, well we're already doing that and it's called Pyrus and will be PHP 5.3+, the work I'm doing on the PEAR installer is because people will take some time to upgrade from PEAR installer to Pyrus once Pyrus is stable so I think it's important we try to maintain the old installer for a bit longer and to make that easier for us the PHP version reduction was important, for us and I believe the community.

I'm mostly making this post so people know about this beforehand and can react accordingly on their own servers when the time comes.

Also does anyone have a beef with me excluding those PHP versions ? :-) If so comment here or email me at helgi _at_ php _dot_ net and explain to me why that is.

Link
Lukas Kahwe SmithA short goodbye to 4.x (8.8.2008, 20:43 UTC)

This includes the end of support for all things PHP 4 as noted by seemingly everybody on php planet. But I also wanted to reminds people that the same is more or less happening in the MySQL world too. Did you know that active support for MySQL 4.x ended along with the year 2006? Did you even know that MySQL 5.0 active support is ending this year!?! Given MySQL 5.1 no show mentality, they might have to review this. Well there is of course extended support that extends MySQL 4.0 support until this year, MySQL 4.1 until the end of next year and MySQl 5.0 until the end of 2011.

Link
Ken GuestPHP 4 - this parrot is deceased! (8.8.2008, 14:15 UTC)
I woke this morning with a grin. Nope, nothing to with the Olympics; PHP 4 is dead and by that I mean it is no longer supported - no more official security updates for PHP 4 - or backports from PHP 5 or PHP 6. The last release of PHP ...
Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR