Personal Project to Benefit Animals

Over the last months I have been working on a personal project of a cause that I care about. Helping more dogs and cats and other pets to get adopted and not fall through the cracks and be destroyed due to overcrowding in local shelters. Petfinder is an organization that a lot of smaller shelters work with and provides an xml api to their data that other developers can use. I have three sites which are based on the same source code and same data, one which has all the information, which has a filtered data set which is for shelters that have cats or specialize in cats and which has the same for dogs.

The sites are built using the CodeIgniter php application framework, which has worked resonably well. I use Zend Framework a lot at work, and I might have chosen Zend if I started today, but for a site of the scale I am working on CodeIgniter works well. CodeIgniter is efficient in design and coding, but has a bit of ugliness underneath the core. I built classes which can make requests to petfinder’s api. For the content that is more constant, I built utilities to pull using the xml api (using the classes) the shelters that I was interested in (I chose the tri-state area). Then the imports were converted using another script into insert and update statements.

For more dynamic content I use direct access to the petfinder api, for instance for a random pet feature they have. Initially the features I didn’t want to build I linked out to petfinder’s site. Later I have built out more. I have also integrated twitter, facebook, the openx adserver, and joomla to help with more content which would involve less building of code. Side bars content is built using jquery using an ajax implementation, allowing the sidebar content to be integrated dynamically, which can come from either random pet pictures, petfinder’s random pet feed or the adserver. To improve the design, I have integrated Webfonts into the site using adobe’s api.

I have wanted to build a state of the art mobile site for this as well. Unfortunately petfinder’s mobile presence is very inconsistent with petfinder’s web presence in terms of url structure and how it can be integrated, so I knew I would have to build all the features that I wanted to present. I have worked with jquery over the years and like a lot of things that this framework can do. I have seen people build mobile functionality with it, but until the jquery mobile came out it seemed much more work. I have been working using jquery mobile which works resonably well. It has some deficiencies, for instance css fixed positioning doesn’t work as well on android 2.3 and earlier, the transitions can be a little jumpy, but in general it works.

Moving from Apache to Nginx with php-fpm

In order to address performance issues we have seen, our company has been switching from apache with mod_php to nginx with php-fpm.

Given that apache httpd webserver is an older code base and does not take advantage of event driven and asyncronous technology this seems to be the future. There are numbers of differences between these two.

Nginx webserver is product that came out of Russia, it had been more obscure, though now it is the #2 webserver. Apache webserver has been an important product in web based technologies for many years, and has been the dominant webserver. Php as a technology is often used in a module in apache (mod_php) or run through a cgi type where php runs in a separate process. To improve performance of cgi type operations the php supports fastcgi. Fastcgi runs a server which keeps a number of php processes live and waiting for traffic and runs them as a server, there are numerous advantages to using this.

At high load apache has been shown to not manage memory as efficiently as possible.

Where nginx really shines is in serving static content, where it’s asynchronous technology allows it to serve more content than other webservers.

Switching to Nginx has required changes, for instance taking out use of apache specific functions like getallheaders() which provides the headers in normal http header form, not in the cgi name scheme that you find in the $_SERVER variable, for instance User-Agent vs HTTP_USER_AGENT, and switching configuration from .htacess files to nginx rewrites.

Configuration of Nginx is different from apache, and ins more scripted than the style of apache.

As far as performance, the verdict is mixed, it can take time to tune nginx and php-fpm. If you are switching thinking it will be a fast win for php applications with peformance problems, think again, you need to look at your code. If you serve a lot of static assets, this might be a boost for you.