Phillip Pearson - web + electronics notes

tech notes and web hackery from a new zealander who was vaguely useful on the web back in 2002 (see: python community server, the blogging ecosystem, the new zealand coffee review, the internet topic exchange).

2006-2-3

Java XML parsing

Useful: a whole book on processing XML in java, free.

(I decided to get the eBay Java code to use the XML API rather than the Java API, which means I need to read and write XML manually, but it'll mean my object code will consist of a few kB of class files rather than a few kB of class files and 20MB+ of jars.)

I haven't found an equivalent of ElementTree for Java, though... although here's a lightweight DOM implementation.

... more like this: []

Debugging PHP crashes (previously: "PHP: don't define functions inside switch statements")

Hmm, looks like some versions of PHP, including the one running on outputthis.org, crash if you call a function defined inside a switch statement. Oops!

---

BTW, if you find that your script is crashing PHP (i.e. your browser gives an error, the server drops the HTTP connection after receiving the headers, and you get an error in /var/log/apache/error.log like [notice] child pid 2706 exit signal Segmentation fault (11)), here's how you figure out what's going wrong - or at least get something to Google.

* Step 1 - enable core dumping in Apache

Edit /etc/apache/conf/httpd.conf (it might be at /etc/httpd/conf/httpd.conf) and set the CoreDumpDirectory option to a directory that Apache can write to. I created a new directory:

mkdir /var/run/httpd-core
chown apache.apache /var/run/httpd-core

... then put this line in httpd.conf:

CoreDumpDirectory /var/run/httpd-core

Now tell Apache to reload config:

apachectl graceful

* Step 2 - trigger the error

Browse to the page or do whatever you need to do to cause PHP to crash Apache.

* Step 3 - find out what happened

Now you should have a file called something like core.1234 in /var/run/httpd-core. This file contains lots of info on what was going on at the time of the crash. You can inspect it with gdb:

cd /var/run/httpd-core
gdb /usr/sbin/httpd
core core.1234
bt

Now you will be given a stack dump. Cut and paste the function name and address from the first line (in my case "0x0000002a9a6ae417 in zend_switch_free_handler") into Google. If that doesn't return anything, try searching for the function name and the word 'crash', i.e. google for zend_switch_free_handler crash.

Now look through the first few results, and if you're lucky, you'll get a page describing some odd coding practise that PHP doesn't handle well. In my case it was this one - "function defined in switch, carshes".

Good luck!

... more like this: []

What needs to happen

Hybrid (amzn) feat. Sheryl Crow (amzn).

Listen to Crow's "Chances Are" and tell me that she wouldn't do better a better job of "Blackout" than Kirsty Hawkshaw...