Phine Solutions web work notes

building a Smarty driven PHP site - 1

Filed under: PHP development — 1.618 @ 10:58 am

The Model, View and Controller (MVC) design has been used widely to develop complex web sites. The key of this design is to separate the data, process and presentation so they can be developed separately and easier to maintain. 

A web server was originally just a file server over the network. It became fancier with more functionalities added and people begin to use it for wider range of things. As a result, web sites become complex applications to run on the web server to provide all kinds of information in the form of the web pages.

To create the web pages, especially the dynamic ones, the web application has to go through the following steps in most cases:

  1. Get the request from the user and decide how to process it.
  2. Once decided how, it needs to know where and then retrieve the information that the user requested, in most cases today, a database stores this information.
  3. After getting the information, the it will format it and present it in a certain way, mostly, in a HTML format.

With all these tasks, it becomes a challenge to write the application because you simply don't want to stuff all these codes into one program.

In the old CGI world, a program (in Perl or C) was written to display a web page, and it would include everything from getting the data from a DB and creating HTML page by calling the function like: print "<html>"… 

Imagine if a designer wants to make some change of a line of HTML code, he has to do the code change, probably through a developer, to make this happen. Even with the help of some tools or scripts for automatic code generation, we have to come up with some new ways so the development process can be easier and the code can be more robust and flexible.

This is the time when the MVC design comes into play. We separate the code into different groups based on what is does:

Controller handles the user's request. It decides which part of the code should be used to process the user's request. With the controller, you can clearly define the flow of the request handling.

Models defines the info retrieval and processing part. For example, if a user points to the browser to a page for sports news, the Model layer will try to search the database to get the them based on the user's request. For example, if the user wants to see NFL news, the program should use the correct query to find the news that are NFL related.

Views basically finishes the work by formatting the information and present it to the user. In a web application, the view program creates the HTML pages and they are eventually sent to the web browser.

The benefit of the MVC design is that it greatly separate the code based on what it does. With this kind of separation, it becomes easier to manage different parts of the application, maintain the small pieces without breaking the others. It also becomes possible that developers and designers can work on different parts of the application without messing up the other's work.

To implement this type of design, some type of framework needs to be in place to connect the different pieces. A developer can certainly write his own, but there have been several well-written open source project out there for us to use.

In PHP world, the Smarty template engine is a great tool to implement the MVC design.

remove the CVS folders

Filed under: cvs — 1.618 @ 7:52 pm

If you use CVS for your code you probably notice that a CVS folder is created under each directory in your code base. I was playing with the code the other day but struggling to get a clean code base because all these CVS folders are in place. After a little bit of researching this Unix command did the job for me:

find . -name CVS -exec rm -rf {} \;

Basically a “find” command can be concatenated with other commands so the same operation can be applied recursively to all the found results.

Since this is a Unix command Cygwin is required to run it on Windows.

in-text advertising

Filed under: my 2 cents — 1.618 @ 12:51 pm

I am more and more annoyed by those in-text advertising float out box now.

If you don't know what I'm talking about, they are the little on screen pop up boxes triggered by your mouse hovering over some text that are double underlined. The content showing inside the box is supposed to be relevent ad content for the text.

The problem is that most of the times the ads are irrelevent, at lease based on my experience. For example, I visited someone's blog and there is mentioning of the "front page of Digg", and guess what in-text advertising showed me? The Microsoft front page product. Unlike adsense ad, if the in-text ads are based only on the selected text, it is a lot harder to figure out the relevant one.

The in-text ad is also a distraction to me since I have to be careful about where my mouse is to avoid them showing up.

Unless those in-text ads become more relevant, they are just another form of the popup window that has been annoying the websurfers for years. Eventually some browser plugin will be developed to disable them.

 

advertising on stumbleupon.com

Filed under: my 2 cents — 1.618 @ 2:55 pm

When starting a new site, it can be difficult to find some initial users and gather feedbacks for a small site with limited budget.

Stumbleupon.com can be a good place to start some advertising and testing on the broad market. If you haven't tried StumbleUpon yet, it's a website that categorizes a big pool of websites and pages and show them to websurfers. A user can setup an account and select the categories that interest him and stumble away by clicking on the StumbleUpon toolbar on the browser. 

To advertise on it, you can create an account and add the URL that you want to be included in its big repository. You can select the category and also customize who you want to show to by selecting the gender, age and geographic location of your visitors through StumbleUpon. Each showing will cost $0.05, and you can put a daily budget by limiting the showing number and max spending.

Once your ad has been approved, you should start seeing the report about how the StumbleUpon visitors think your website. Unfortunately right now there are only 3 opinions, like, dislike, or neutral.

What I like about it: 

I believe the StumbleUpon users are early adopter of new things on the web. So they are more likely to viral marketing for you if your site is really a hit. Plus and your visitors are those who are interested in the subject so they are more likely to be your targeted visitors in the first place.

Although most of the stumblers choose not to rate (at least in my ad experience), you can still get some feeling about the acceptance of your site. Granted, if most of your feedbacks are negative, there is definitely something you want to look into.

How can StumbleUpon improve the system:

If StumbleUpon can encourage the stumblers to rate more and even add some comments besides like or dislike, it will be a hugh help for advertisers. I would even create some power user groups system and pay them for rating and commenting (Well, this may be already in place under the cover). This would attract more advertisers since the system essentially offers a focus group to the web designers. And if you can get a thumb up/down and a small comment for 5 cents, it's a pretty good deal.

scratching the surface of DNS

Filed under: server setup — 1.618 @ 11:19 am

DNS stands for Domain Name Server (or System). It provides a "directory" like service to map a domain name to a IP host. The setup and configuration of DNS is critical since it can make a website "invisible" on the internet if not done correctly. Understand the basic stuff can make this process a lot easier.

First, some terminologies and tools that can check for DNS setting

DNS uses has different record types to define a domain. The most used one are as follows:

A - stores the host ip address CNAME - alias record, for example, www.phinesolutions.com is the alias for phinesolutions.com

MX - mail exchange record which tells mail server how to route emails.

CNAME - Canoical name: Used to assign aliases to existing A records, for example, a domain.com can have other alias such as www.domain.com, ftp.domain.com…etc.

Once the basic meanings are clear, you shouldn't have too much trouble to read the report from www.dnsreport.com , where you can spot the DNS problems with your server and make changes.

If you have access to a *nix system, the "dig" command can be very helpful too:

dig www.phinesolutions.com tells me the A record for the domain.

dig phinesolutions.com mx tells me the MX record.

Notice we lose the "www" part because we really need to check the domain name without it. People use email address like email[at]phinesolutions.com, instead of email[at]www.phinesolutions.com.

dig is a powerful command and you can certainly dig out a lot more information than above. A look at dig man page should make a nice guide on this.

 

Next, is an example of using BIND to run a DNS service.

BIND - Berkeley Internet Name Domain

BIND is an implementation of DNS protocols. It includes a set of components that are necessary to run and maintain a DNS server. The BIND package is installed on the vast majority of the DNS server machines on the internet.

Named

Named it part of the BIND package and will run as a Daemon process to handle the DNS requests.

/etc/named.conf

This file serves as a name server configuration file. It provides the settings for named to run. Most of the settings do not need to be changed. But to add a domain name to a name server, a "zone" setting has to be added into this file, like the one below:

zone "phinesolutions.com" { type master; file "/var/named/phinesolutions.com.db"; };

This basically tells named that it should handle the request for domain name "phinesolutions.com" and the zone file for this domain is /var/named/phinesolutions.com.db.

A "zone" is not necessarily mapped to a domain name, it can also be mapped to a sub-domain name like "my.phinesolutons.com".

zone file

A zone file, for example "/var/named/phinesolutions.com.db" in the above example, tells the DNS server HOW to keep this zone record. For example, how often should the server updates other DNS servers about the whereabout (IP) of this domain. Here is what is looks like:

zone file example

To understand this, we need some explanation:

  1. Throughout the file, there are numbers like 14400 and 86400, they are the Time To Live (TTL) value. It defines the length of time, in seconds, a particular zone info is valid. As you can see in the beginning of the file, "$TTL 14400" sets the default value. And the individual records have their own and can overwrite.
  2. SOA - Start Of Authority. This specifies the primary name server for this domain name and a set of values that are related to the name server. I am going lazy here, if you need to understand what they are for you can find it from this RedHat documentation.
  3. NS records. Again they define the primary and secondary name servers for this domain. 
  4. A record, like explained in the previous section, shows the IP that this domain is pointing to.
  5. MX record points to the same sever since I have the mail server running on the same server. Multiple MX records indicate the multiple mail servers for the domain. And the number 0 shows the priority of the server.
  6. My CNAME records include www, mail and ftp. So if a user tries to access www.phinesolutions.com, ftp.phinesolutions.com or mail.phinesolutions.com, the name sever knows where to point them to.

Once you have one working zone file in place, it can be used as a template for the others. The zone file has some special format, such as the "." following each domain TLD. They have to be there or it won't work.

With a host management tool such as Cpanel, all these can pretty much configured through a friendly UI without getting down to the dirty work of file editing. However, knowing these simple concepts can help you better understand the process and know where to look into when needed.

4 google tools that I enjoy using

Filed under: web 2.0 build 1 — 1.618 @ 11:24 am

Google lab (labs.google.com), as the name suggests, provides users or developers experimenting tools and APIs to try. These 4 tools are the ones that I enjoy using the most.

Google reader (google.com/reader)

With Google reader, I can read the fresh new content of my favorite sites in one place. For example, to add a blog, I just click on “Add subscription” and type in the URL, and the blog is pulled down on my screen right away.

Google notebook (google.com/notebook)

With this tool, your web surfing can be a lot simpler. Once installed, you can add text, images or links to your little scratch book. Often times, we only need to put down the pieces instead of bookmarking the whole site. And Google notebook will just do that.
A little link to the notebook will also be created on the right bottom corner of the Firefox browser for you to open the notebook on any computer as long as you are signed in using your Google account, so it makes it a lot easy to retrieve the information that was saved from another computer.

Google Doc (docs.google.com)

This is the Google’s effort to bring the Office applications online. It’s browser based tool for office document editing online. Right now it only supports “Word” like document and spreadsheet. You can upload your word doc or Excel spread sheet and they will be automatically converted. Although they are not as fancy as Microsoft Office, they have enough features for a regular user to create a decent doc and spreadsheet and get the work done. With this tool, a user can edit the docs from any computer and share them with other people.

Google browser sync

Since I am using Firefox on my office and home computer, this tool helps me to sync the settings between the browsers. The one I like the most is the bookmark syncing. If I needed to sync my bookmark before, I had to export the bookmark, email it to myself and download to another PC and import bookmark. With this tool, they will all be sync up using my Google account and a PIN.

« Previous Page

©phinesolutions.com