Tag Archive for 'how-to'

PHP optimization tricks

Here’s an article I came accross with some interesting PHP optimization tricks. I found the last one, about faster array access, particularly interesting/surprising.

Mac OS Forge

This is SO great: Apple has gotten on the cluetrain and deployed Mac OS Forge, a source control and issue tracking system for various open-source Apple projects, including Darwin. This isn’t just a place to download sourcecode and a one-way bug entry system– this is a full-blown, vanilla deployment of Trac, sitting on top of an SVN server! This is such great news. I’m sure Apple will find that they only benefit from this degree of transperancy and interaction with developers.

And as an added treat, we can see that in addition to their two existing open source projects, darwin and webkit, they are opening up a few more projects– a calendering server, launchd, and bonjour. Nice!

At ibiblio I’m in charge of an svn/trac service that we are eventually going to open for business. Everything is set up and we could go forward with it today, but I am patiently waiting for Trac 0.10 to be released. It has a smattering of features that will be nice to have when managing several or dozens of projects, such as spam control, web administration, and most importantly, mysql instead of sqlite.

The open source development model works, or: why I need to RTFM

When upgrading from MySQL 4 to MySQL 5 on the machine on which the Lyceum blog, Lyceum demo installation, Lyceum wiki, and teachfor.us are hosted, I came across some serious problems. The MySQL daemon would quit unexpectedly, seemingly whenever a query from the demo installation was made, but not any other queries. We checked everything and hunted around the logs and couldn’t come up with anything, so I filed a bug with MySQL. The geekier of my readers may be interested in skimming through it.

The day after I filed the ticket, Heikki Tuuri, the creator and maintainer of InnoDB, was on the case. He and Valeriy Kravchuk let me know how I could provide them with as much information as possible for them to use to debug the problem. Eventually I ran a table optimize, and that fixed the problem. Also, over at ibiblio, we discovered that /var had been at 100% when I was doing an application upgrade (not the DB upgrade), so I figured that might be part of the problem as well; the index got currupted when being rebuilt.

In spite of my findings, at the end of the the thread, I was informed by Valeriy that because of the datatypes in my table, the only way to do a proper upgrade was to dump the table and then reload it after the upgrade, and she directed me to this document. I don’t know if other folks at ibiblio who were working on the upgrade had read this, but I know I hadn’t.

So I’m pleased with the responsiveness and community of the developers of MySQL, and I hang my head in shame for not having RTFM.

Lyceum article in Red Hat Magazine article

I was asked to write an article about Lyceum in Red Hat Magazine. Here it is!

Awesome.

Infinite Redirect

Apache 2 follies

I was trying to get a pretty simple Apache 2 virtual host configuration together and for some reason Apache refused to start up. I tested the configuration with httpd -St and everything was fine. I started httpd with full debug reporting on (-edebug) and got no error messages. But apache would silently fail to start.

My general expectation is that programs will give feedback at the terminal if they fail, so I didn’t think it was necessary to check Apache’s logs while debugging configuration problems. But I was out of ideas so I fired up a tail -f /var/log/httpd/error_log and tried again. Sure enough:

[Sat Apr 08 16:22:00 2006] [error] (2)No such file or directory: could not open transfer log file /www/hosts/www.domain.com/logs/access_log.
Unable to open logs!

The logs directory didn’t yet exist. I created it and Apache started up just fine. Without it, Apache refused to run!

At first this infuriated me. But then I thought: maybe this is the preferable behavior for server software. It’s one less variable to worry about — if my website is up, I know that its logs are working.

Systems folks: what do you think? Should daemons refuse to run if their logs aren’t working?

Independent of if it runs or not, I think that Apache should give feedback at the console (in addition to the logs) when it isn’t starting properly. If I had restarted my daemon and gone to lunch, I would never have known that there was a problem!

MySQL Index Types

The documentation for MySQL index types is hidden in the page on CREATE TABLE Syntax and isn’t as clear as it could be. Here’s an overview. (some of this is pretty obvious but I’m erring on the side of redundancy).

  • KEY and INDEX are synonyms and mean that the colum should be indexed, and do NOT require the column to be unique
  • UNIQUE is unique
  • PRIMARY KEY:
    • is an index
    • implies that all the columns are UNIQUE
    • all columns in the key must be defined as NOT NULL
    • a table can only have one PRIMARY KEY

Let me know if I’m missing anything.

How to use RPMs

Some info on using RPMs, from some questions I asked fellow ibiblian Jon Mills:

pardom my enduring systems ignorance — where does one get rpms? i know that projects distribute them themselves… were some or all of the ones you installed provided by red hat?

RPMS are voodoo. No, redhat provided none of the rpms you asked for. It’s difficult to find binary rpms for specific linuxes (except for really popular, non-proprietary ones, or unless the distro provides them). If you can’t find a binary rpm, what you do then is to try and find a source rpm, which always looks like <package-name>.src.rpm. Source rpms let you compile from source, but it compiles it into an rpm, rather than just splattering it all over your filesystem. You run this command:

$ sudo rpmbuild --rebuild --target=`arch` <package-name>.src.rpm

It will try to compile and roll the binary rpm for you. If it fails on a compile dependency, then you try to auto-install that dependency:

$ sudo up2date --install <dependency>

If that doesn’t work, then you do this whole process over, except with the aim of just installing the dependency. So you look for binary or source rpms for the dependency, get it installed, and then go back to where you were.

This usually works pretty well. The only time you run into trouble is when you’re trying to install something which supersedes a package which lies within a huge chain of dependencies, such that removing it or upgrading it breaks dozens of other packages. This is called dependency hell, or RPM HELL. Upgrading PHP is a good example, because it has hooks into apache, mysql, and a ton of libraries–you can never just upgrade PHP.

for something like subversion, where it has several binaries and also some apache modules– does the rpm intelligently find the apache install and put the modules somewhere appropriate? do rpms ever actually modify config files for you?

The intelligence is in the rpm spec file, which must be written for each specific distro. That’s how the rpm knows how to find things. If all the spec files are well-written, then everything knows where everything else lives, and all is well.

rpms can modify config files, using shell scripts that get executed after the install. The shell script would be included inside the rpm, and called from the spec file. A good example is that when you install a linux kernel using rpm, it adds an entry for that kernel in /etc/lilo.conf or /boot/grub.conf.

Effortlessy switching between php4 and php5 for web development

I want to test my software on both php4 and php5 quickly and easily. Here’s the solution I came up with.

First, take out everything regarding php out of your main apache config. LoadModule phpX_module ..., AddModule mod_phpX.c, and anything else.

Next, make three files in the same directory as your apache config (/etc/httpd/ on OS X):

php4.conf

LoadModule php4_module        /usr/local/php/libphp4.so
AddModule mod_php4.c
Include /etc/httpd/php_stuff.conf

php5.conf

LoadModule php5_module        libexec/httpd/libphp5.so
AddModule mod_php5.c
Include /etc/httpd/php_stuff.conf

php_stuff.conf

AddType application/x-httpd-php .php

<IfModule mod_dir.c>
  DirectoryIndex index.html index.php
</IfModule>

Now add this line to the bottom of your httpd.conf:

Include /etc/httpd/php.conf

Now make the following two shell scripts and put them somewhere like ~/bin:

p4

cp /etc/httpd/php4.conf /etc/httpd/php.conf
apachectl graceful

p5

cp /etc/httpd/php5.conf /etc/httpd/php.conf
apachectl graceful

Ta da! Now to switch between php4 and php5, you can just do sudo p4 and sudo p5.

It would be nice to even tie this into an applescript with some sort of dock or even menu bar presence… if anyone has any tips on how this might be done let me know.

Programmer needed in Austin

My friend Zane is hiring a programmer in Austin.




Close
Powered by ShareThis