Tuesday, February 28, 2012

PHP libxml issue while compiling

Today I had some trouble getting libxml to work in PHP. I was compiling PHP 5.3.10 for a client's Joomla site and it needs libxml. The issue seemed to be commonly happening to many people and I came across a number of forum threads on the topic.

The suggestions mostly hover around installing libxml2 development package. This can be done in Debian or Ubuntu by:
apt-get install libxml2 libxml2-dev

On other Linux distributions you may try libxml2-devel

But I had already done that and still libxml was not showing up in PHP. I had the --with-libxml-dir setting in ./configure with no luck.

Then I came across the --enable-libxml setting, which although is not mentioned directly in the `./configure --help`, it should have come to my mind. This is how you enable (or disable with --disable) any module from the ext/ directory. Anyway, I found it mentioned here and that worked! The reason for this is because I had --disable-all option set. So all default modules were off, and I had to enable libxml with its enable option.

Hope this helps someone else...

Friday, February 17, 2012

Building a Yii app: The Data Model

A friend of mine needs a web application to be revamped. I had originally created it about 2 years back using a custom PHP mini-framework that I had built for many projects at that time. The development had stopped for different reasons and parts of his web application were incomplete. For example images were not upload to Amazon S3, which was originally planned. Some Model edits were not working in many parts and there were some data validation issue. He has been doing the groundwork for his business and now has decided to finally complete the application.

The application is related to Medical needs, information about patients, doctors, hospitals etc. I have decided to make the new version using Yii, since some other developer will take over if the project is successful and Yii (or other popular frameworks) is a very well documented framework for anyone to use. The choice of Yii against other PHP frameworks is rather just an impulsive one. I have read comparisons of the good PHP frameworks and Yii is among the top few. Anyway moving on...

While I am building this application, which is a moderately feature rich one, I intend to write about my experiences. Hope this helps anyone looking for a quick introduction and example for Yii. I am trying to make this a tutorial for Yii, I will try my best here. The project needs data for multiple types:
  • General User Profile (could be a patient)
  • Doctor
  • Hospital
  • Nursing Home
  • Other Medical companies like: Medical Shop, Diagnostic Center, Fitness Center, Ambulance Provider, Nurse, etc.

Other information include:
  • Specialization: this is related to Doctors, explained below
  • Address: City, State, Country, etc. Any entity can have multiple addresses
  • Phone: can be either a fixed or a mobile (cellular) phone. Any entity can have multiple phones, also address can have phones associated with them
  • Department: Hospitals or Nursing Homes can specify many departments
  • Branch: Hospitals, Nursing Homes of Other companies can have multiple locations/branches.
  • Image: multiple images for any entity.
  • User: this is used for authentication, simple email/password for now.
In order to manage the mappings of many entity types to Address, Phone, Branch, Image etc. I have used a central Entity table. Every type of physical entity has an entry in the Entity table (including each branch). Then Address, Phone, Branch, Image, Department are mapped to Entity table.

In Yii terms the relations look like this:
  • Doctors can have one or more Specialization (HAS_MANY in Yii Model)
  • Doctor, Hospital, Nursing Home, Other, Profile have a one-to-one mapping to Entity (BELONGS_TO in Yii)
  • Entity can have multiple Addresses, Phones, Images (HAS_MANY in Yii)
  • Entity can have many Departments (HAS_MANY). This is limited to only Hospital, Nursing Home or Other types though at the application level.
  • Entity can have another Entity as Branch (HS_MANY). This is also limited to Hospital, Nursing Home or Other types at the application level.
I will write about setting up Yii Models in the next blog entry...

Saturday, February 04, 2012

Trying out non AWS options

I have been using Amazon Web Services for all of my (or companies' I work with) compute or storage needs for the last 4 years. That include AWS S3, EC2, SimpleDB and even RDS (at MobStac). For the last few weeks I have been planning the platform choices for Mag. It does include AWS DynamoDB, S3 and EC2, but the picture is a bit different.

Amazon DynamoDB guarantees a lot of performance and I personally do not want to take database headaches. DynamoDB pricing model is great to start with too. It is not cheap, but does not bite at the same time. And you continue paying as you grow. The data model is similar to other NoSQL services and you can shift out later if you want.

AWS S3 is a really reliable, cheap storage solution and there is no doubt we will use it wherever we need. EC2 is great for its scalability or its powerful solution to failure handling. Bringing up a pre-configured EC2 (many data centers around the world) is fast, easy and cost per hour is cheap.  Also extra processing as and when needed is perfect fit for EC2 Spot Instances.

While AWS EC2 provides all these great services, hosting regular websites and serving traffic is still costlier. Bandwidth is premium inside AWS. Yes they are very well connected, but you can get that from many top quality hosting providers/data centers. Also the machines themselves are not as fast as a good VPS could be. I have been searching for VPS providers with SSD storage, newer processors and RAM. Recently I tested a tiny VPS (384MB RAM) with such configuration and the Apache Benchmark shows better performance than an AWS EC2 instance (Ubuntu, nginx, PHP, APC, apc.stat=0). Although PHP on the VPS was compiled, and I will re-run the tests, but the difference was very visible.

Of course I do not intend to co-locate or manage any hardware. But I certainly want to look at good VPS or unmanaged dedicated offerings. Configuring a VPS/server is not easy too, from firewall to internal network if you run a cluster, but if the pricing differences are worth it, then it makes business sense. And EC2 is never out of the picture. They will be used in parallel but for stuff I mentioned above and not for regular traffic.