PHP for Regular Scripting

I had this cronjob that was doing some work for me. I chose to write it in Python and figured it was pretty fast. The task involved querying a MySQL database and for each item retrieved (about 500 of them) doing REST web service requests to get some XML back.

I'm a lot more proficient with PHP than Python and enjoy the documentation a lot more.

I decided to rewrite the script that cron was running using PHP, since I saw an article saying PHP could be used from the command line (CLI).

Surprisingly, the PHP version turned out to be quite a bit faster; about 6% actually. In the Python version, I used a library very close to the pure expat implementation. For the PHP I used SimpleXML which is higher-level and a lot faster to write code in. I would have thought the Python would be hands-down faster.

I tried PHP4 (simple XML routines) and PHP5 binaries, and in praise of PHP5 and SimpleXML, they were not noticeably different than PHP4 times.

Some times: for 10 items, Python took 12.37 seconds while PHP took 11.65. For all 500 items, Python took 2m13s, while PHP took 1m19s (for the core processing...each script had sleep calls that added a flat 10 minutes)