fogbound.net




Sat, 7 Jan 2006

Ker-Ash!

— SjG @ 12:03 am

So, courtesy of the DWP, the Meier Quagg was without power for about 7.5 hours today. It’s not clear what was wrong. The other side of the street had power, as did several parallel streets nearby, but this side of Meier was out, as were patches of Venice like the Oakwood.
Anyway, when the power came back up, most of the servers came back with it. Intervention was required for the Golem, Pylonhead, and Sekhmet. Sekhmet was the worst. I only got the “LI” of LILO, which says that the /boot/boot.b file was bad, or the drive geometry was hosed.

So I tried my trusty Debian rescue disk. Typed rescue root=/dev/hda1 at the boot: prompt. The boot failed with a complaint that /dev/hda1 was an MSDOS partition. uh-oh… MSDOS?

Of course, it turns out that I was using the wrong rescue disk. I was using a Woody ISO, and I had upgraded the machine to Sarge — and EXT3, which evidently was not compiled into the rescue disk. When I finally tried the correct rescue disk, it came up neatly, repaired the journals, and gave me my precious root prompt.

I did the LILO replacement trick (lilo -u /dev/hda; lilo), popped out the CD, rebooted, and held my breath. Then I decided to breathe. It’s my second fastest server, but it’s still a four-plus-year-old Dell Optiplex. In any case, it came up cleanly and there was much rejoicing.

Now it’s just a matter of waiting for the mail secondary to forward on all the queued up spam.


Tue, 25 Oct 2005

PHP4 and PHP5 under Windows

— SjG @ 4:02 pm

There have been other articles on this, but I wanted to post my own approach, just because it’s such an ugly — yet effective — hack.

I wanted PHP 4 and PHP 5 to both live happily on my Windows 2k machine, and work under Apache 1.3x. Install them in c:\php4 and c:\php5, and there you go. It’s easy to create an httpd.conf that takes a define, and figures out which PHP to load based upon that define.

But then both PHPs want to use the same php.ini file, specifically, c:\WINNT\php.ini. This is only a problem when you’re using PHP extensions, because one version will try to load the wrong ones. There are registry tricks, supposedly, and environment variable tricks to get different .ini files going, depending on version. None of ’em worked for me.

So I opened up vim, and edited my php4ts.dll, and replaced the “php.ini” string with “ph4.ini”. Now I happily have two PHP installs, each with its own .ini file, and everything is copacetic — except for all that software that breaks the newly enforced reference rules. But that’s another story.


Sat, 24 Sep 2005

AJAX

— SjG @ 6:41 pm

So, while the core development of CMS Made Simple is undergoing some interesting (and pervasive) updates as we head towards a 1.0 release, I’ve been fixing modules to work correctly under PHP 4.4 and 5.0.5. Obviously, my understanding of references was weak, and I’m paying the price now. Damn, I wrote a lot of wrong code.

But now I’m playing with making an alternate Admin interface for CMS Made Simple using some of the fine AJAX and Javascript libraries out there.

I’m using xajax to marshall up objects and submit them nicely to PHP, and I’m using the script.aculo.us Web 2.0 and its underlying Prototype library for User Interface and special effects.

Some of it’s silly, like making the login box shake if you incorrectly enter your username or password (imitating Mac OS X login). But some of it is really slick — adding users to groups is now as simple as dragging’n’dropping items between lists. It could use a way of multi-selecting that worked with dragging, but an “add all” and “remove all” button mitigate that somewhat. Of course, the original interface will remain for non-Javascript users or people who prefer it.

I plan to do the same for assigning permissions to users. But the real challenge will be drag’n’drop content reordering. This will require a draggable tree. I haven’t yet found code to make this easy; even with all these great libraries, I have to be careful to select features that work equally well under the Evil of Internet Explorer, as well as Gecko-based browsers and Opera…


Wed, 7 Sep 2005

Build PHP 5.0.5 for Mac OS X 10.4

— SjG @ 8:39 pm

I’m trying to track down a bug in my CMS Made Simple PHP code where I did something stupid with references (a rant on the PHP pass-by-value model available upon request). So it only manifests with PHP 4.4.x or PHP 5.0.5, since that’s where they finally decided to get strict with us idiot slackers. Neither of these are available as binary packages on Mac OS 10.4.

I was dismayed, shocked, stunned, dazed, and confused to learn that PHP was no longer a package for Fink. Dammit! Now I have to figure it out for myself. Crap.

With the help of a variety of pages out there on the web (especially this one), I was able to do it. Here’s how:

Install Fink, if you haven’t already. I use the “unstable” packages. Read the FAQ, and muck around with it for a while until you feel ready to proceed.

Install a wholehellovalotta packages using Fink:

  • libjpeg
  • libtiff
  • libpng
  • libxml2

I also installed the Fink version of MySQL server 4.1, client, and a bunch of shared libraries.

Next, gotta build ZLib:
curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/sw
make
(su if necessary)
make install

(I did my install work in /sw/src, but you could do it somewhere else if it pleases you more. Just take note of this other location when you need it later.)

Finally, we get PHP 5 .0.5 from http://us2.php.net/get/php-5.0.5.tar.gz/from/a/mirror

tar xzvf php-5.0.5.tar.gz
cd php-5.0.5
./configure --with-libjpeg=/sw --with-libtiff=/sw --with-libpng=/sw \
--with-gd --with-mysql=/sw --with-xml --with-apxs --with-exif \
--with-jpeg-dir=/sw --enable-exif --with-png-dir=/sw --with-zlib-dir=/sw \
--enable-embedded-mysqli
make
(su if necessary)
make install

Now, I already had a version of PHP installed before this, provided by Marc Liyanage’s excellent binary packages available at his page, so I didn’t need to tweak my php.ini file. If you do, you’d probably do something like:

cp /sw/src/php-5.0.5/php.ini-recommended /usr/local/lib/php.ini

and then edit into submission. You can also use the more general php.ini-dist instead of php.ini-recommended. I don’t know why they provide both — probably to confuse idiots like me. You’ll also need to register the PHP Mime Type with Apache. Edit your /etc/httpd/httpd.conf file, and add either to the general area or to a specific virtual host the line:

AddType application/x-httpd-php .php

Now test it! Create a test file in your web root containing:

<php phpinfo();>

and browse on over to it. With any luck, you’ll be greeted with ahappy PHP 5.0.5 banner.
Celebrate this with red wine. Preferably good red wine. Then get back to coding. As should be obvious, I decided to document instead of code, but I didn’t skip that vital red wine step.

Enjoy!


Thu, 3 Mar 2005

Feedback Form Module, Newbie Software Engineering

— SjG @ 12:12 am

So I’ve just finished version 0.4 of a module for handling user feedback for CMS Made Simple. It allows users with administrator rights to create reasonably complex forms, with all the user interface objects that we’ve come to expect, and handle the submission of those forms in a variety of ways.

It’s been an interesting experience. Version 0.1 was your standard naive PHP implementation of an application within a framework. It was all one big script in one big file. It would do fairly simple database queries, stuff all the results into a big array, and then process array elements with big switch statements when it needed to customize output based upon UI object type.

Version 0.2 ported this basic functionality into an Object Oriented model. I found that there were a couple of complex decisions to make — should I handle the database storage and retrieval in an OO manner? And if I query a bunch of Input Objects from the database, how do I know what specific kind of object to instantiate since that data is contained in the database record? I guess the truly OO approach would be to use an OO database, or, next best approach, to have a separate table in the database for each kind of input object. But that’s not how I did it, probably to the detriment of my code (I instantiate a superclass object, then use the type details from the general object to create a new object which is the correct specific class.)

Still, this showed how a procedural approach could save a lot of database activity over an OO approach. The data model comprises forms, which contain one or more fields, which have one or more options. In the procedural approach, I denormalize the database so that fields contain the form id, and field options contain both the field id and the form id. I could then grab everything I needed for a form in three queries. With the OO model, the number of queries is proportional to the number of fields. What’s more, there’s been a massive proliferation in the number of files required. While I worry about the web server having to load and parse all that stuff each time, I should probably have more faith in the PHP engine and the OS caching. As a number of people have said to me, I’m not playing on a TRS-80 with 4k RAM anymore. But I still feel like I should be programming as if resources were seriously limited.

Similarly, when it came time (for version 0.4) to add localization of the code, it required some somewhat unpleasant contortions: each Input object needs to have access to a global collection of text strings (stored in a big hash) so they can present localized versions of messages. And I still need to go in and make sure that I’m actually handing around references rather than the copies that PHP likes to pass.

Maybe this is just the yammerings of someone who should understand software design better. Clearly, there were some bad decisions made in the code, although I could argue about how bad they really are.

Another aspect that took me by surprise was how I could test code and have it perform perfectly, while other users reported errors and bugs immediately. In this case, the main culprit was not inattentiveness (in testing, anyway), but my PHP configuration. If you allow output buffering, PHP gracefully handles output before the headers have been sent. Not so, if output buffering is disabled. So when my code would generate errors, my test configuration would blithely allow error codes to be output but then clobber that output with the expected page output. So while I thought output buffering was only involved in performance, it seems that for development, it should be disabled. That way, those bugs cannot be so easily overlooked.

Filed in: