Tag Archives: php

PHP command line mode detection

Use a block like this in PHP code to detect whether or not it's running in command line mode as opposed to web server script mode.

// if $_ENV['SHELL'] exists, we're probably in command line mode
if (array_key_exists('SHELL', $_ENV)) {
} else {

Leash and Feedparser

Maybe I'll write up something a little more formal in the future. For now, I just want to publish this in case it's useful to someone.

Les Orchard posted a blurb that indicated that he was looking for a PHP class to perform HTTP requests with conditional GET support. Well, a while ago I was looking for that, too. Because I was working on a replacement for Magpie RSS (see below), I decided to use Snoopy as my HTTP client. I then wrote a brief extension, Leash, to provide a cache-enabled front end to Snoopy. Leash automatically caches the HTTP results, the time of the request, and the Last Modified and Etag HTTP headers. When you request a page you've previously requested, Leash first checks to see if the cached copy is older than the maximum cache age you've specified (or the default of 1 hour), and if the cache is too old, Leash performs a conditional GET. The latest version of Leash (which I bundle with Snoopy) is in my Subversion repository.

Also in that repository is my replacement for Magpie RSS. I always liked Magpie, but it didn't quite work for me and I also wanted an OPML parser. So I wrote one. Actually, first I wrote a generic PHP XML parser. Then I wrote the OPML parser and Feed parser.

Sorry, but I currently don't have time for documentation. Or support. That probably makes this of very limited utility to all but the most daring. If you're a PHP junkie, you'll probably be able to peruse the code and get the gist. And here's an example of how I'm using it to help manage my podcasts.

Resolution of trouble with CentOS 4 + PHP 5.1 + Zend Optimizer

I have a server running CentOS 4.4 updated with the PHP 5.1.6 from the testing repository. When I tried to install Zend Optimizer 3.0.2, I ran into this problem:

Failed loading [path]/ZendOptimizer. so: [path]/ZendOptimizer. so: undefined symbol: match

Then, when I tried to downgrade and install Zend Optimizer 3.0.1, I ran into this problem:

Failed loading [path]/ZendExtensionManager.so: [path]/ZendExtensionManager.so: failed to map segment from shared object: Permission denied

I noticed some talk about SELinux being a possible culprit, but rather than disable SELinux, I decided to try and solve the problem.

This article about SELinux and ColdFusion MX in Red Hat Linux 4 had the information I needed to quickly solve the problem. Basically, I needed to change the security context of the Zend extension manager and optimizer files so that Zend runs in the same security domain as the web server (in my case, Apache).

Here's what I did (note, I installed Zend Optimizer in a non-standard location -- /usr/include/php/Zend rather than /usr/local/Zend):

chdir /usr/include/php/Zend/lib
chcon -R --reference=/usr/sbin/httpd *.so
service httpd restart

Et voila!
Zend Working Screen Cap

A River for NewsGator

Truly re-inspired by Dave's injection of interest into mobile news reading, I've been tinkering with my own custom solution. Since I subscribe to NewsGator, I'm using the NewsGator API for some backend, but I've done quite a bit of plumbing myself.

The most important things I wanted to be able to do were (1) to be able to mark posts read (and since I'm using NewsGator, that "read" status synchronizes across all my aggregator clients on different computers) and (2) to fix the annoying nonsense characters introduced by idiotic feed generators -- that includes the New York Times and Washington Post.

The results are starting to shape up nicely.

Here's the main page I see after I sign in.

NewsGator River screencap 01

And notice that in FeedDemon, "Chávez" is screwy, but I've got it right.

FeedDemon screen capNewsGator River screencap 02

Optimal OPML Browser Update v. 0.4

I've completed a major rewrite of my OPML browser, Optimal.

I didn't manage to document all of the changes, they were so numerous. Highlights are:

  • Object-oriented reimplementation, making it more portable to other applications
  • Same code may be used as a WordPress plugin -- replaces the OPML Renderer plugin for WordPress
  • RSS items now include descriptions, so you can browse the feeds without subscribing or visiting the home page
  • New widget generator to generate HTML to include Optimal on your web site

More... | Download

Optimal OPML Browser Update v. 0.4pre1

I'm still working on a significant rewrite of my OPML browser, Optimal, but I've decided to release the current working version in the meantime because it addresses a couple of significant usability comments I've had.


  1. There are now links to expand/collapse all nodes, and
  2. There is a new query string parameter, depth, which allows you to specify the initial expansion state.

Optimal Screen Cap 0.4pre1

Del.icio.us to OPML + Mash

I've still got some work to do, so this is just a "hey, it works" sort of post.

John Tropea posted last week about an OPML hack for del.icio.us to which I responded with a more dynamic example and to which another reader asked, "Why bother?" Fair enough quesiton, and here's a better answer by way of example.

I’m using MySQLicious to mirror my del.icio.us bookmarks to a local database (for several good reasons). Now that I have a local copy of those bookmarks and all the del.icio.us tags and other del.icio.us metadata, I can remix it however I want.

The first thing I've done is create an OPML file on-the-fly, where every del.icio.us bookmark is rendered as an RSS feed item with the bookmark's URL as the feed htmlUrl and the xmlUrl is an RSS feed of a Feedster search on the bookmark's URL.

Here's the raw OPML file.

Here's how it looks in Optimal.

Notice that there is a query string parameter "addfeeds." Without this parameter, the OPML is simply rendered as a link list. An addfeeds value of "feedster" adds the search feeds. Eventually, I'll have some additional query values I could use here, such as Technorati.

Here's the source.