2009/03/16

A little better practice on web development

Every time working on a new project, I do it on the development box, after getting code done and tested, I load new code to the production. It sounds simple, isn’t it? But sometime it is not that simple, for the environment between production and development is different, so I cannot just simple overwrite the production one when load the new code in, also, sometime I directly changed the code on the production for a small change without updating the code on the development. (not a good practice though, but for the small company’s website, which may a quick way.)

So I think I need some good practices to follow when I start a new project. Here they are,

1. Before change any single file, compare it with the production one. If see any new in the production (usually a very small change), update it back to the development one. Make sure it works on development.

2. Make a copy of the file you are going to work with. Add it into the project’s file list.

3. Work on the files on the development box and test.

4. When code ready, compare each file on the project’s file list, and double check the different between new file and backup file, and make sure any additions also available on the production. 

5. Before loading the new code into production. Make a copy of the code on the production as filename.OLD. Make necessary change on the development code to meet the production’s environment and save as filename.NEW.

6. OK final step, check the order of files need to change, for a big project, the code updated may be done after 9:00pm. Basically it is copy filename.NEW to filename.

In any failures above, just copy the filename.OLD back to filename.

2009/03/15

Error: Permission denied to call method Location.toString

I got this error in both Firebug and Firefox add-on Web Developer . "Error: Permission denied to call method Location.toString", when visiting my own website.

I checked carefully of the webpage, but did not find any problem of my code. Finally, I found the problem was from a Flash Ad. from Google AdSense.

Anyway, I need to keep Ad.

2009/03/13

IE Security Warning

Most of time I am using Firefox, so I just found that the checkout page of my company's website has a problem in IE today. We bought the SSL certificate, so it is start with 'https.' However, when the page loaded in IE, it prompts,

This page contains both secure and nonsecure items. ...

secure

For user, the solution is that changing IE securtiy setting to display mixed content. Internet Options -> Security -> Custom level -> Enable Dispaly mixed content (in the middle of settings box, took me some time to find it :-))

By default, IE prompts when it see a mixed content page, so for developer, solution is to fix it other than telling user how to change the security settings. How? The reason of this warning is that in the page has both 'https" and "http" links, for example, some images links using 'http'. So changing those "http" links to "https" will fix it, at least in my case.

Updated: (3/16/09)

Actually it depends on how you registered the SSL domain, if it is www.yourdomain.com, then no matter you use http or https. if it is secure.yourdomain.com, then you should correct www.youdomain.com to secure.yourdomain.com.

2009/03/09

XML Parsing Error: Junk After Document Element

I got this error, XML Parsing Error: Junk After Document Element. My XMl was like this,

<?xml version="1.0" encoding="iso-8859-1" ?>
<billing_id>1234</billing_id>
<f_name>adam</f_name>

After some searching, I knew why,

A well-formed XML document must have one, and only one, top-level element. Anything after that element's end-tag will be ignored at best, and possibly reported as an error such as the one you're getting here.

So I fixed the problem by adding a top-level element <rsp>

<?xml version="1.0" encoding="iso-8859-1" ?>
<rsp>
  <billing_id>1234</billing_id>
  <f_name>adam</f_name>
</rsp>

2009/03/06

AdSense shows a blank space

I created an AdSense account a few days ago. But when I integrated it into my website, it only showed a blank space where I put the code without any contents. I googled the web and did not find a solution. Looks like not too many people have this problem, in case you get the same problem, here are some possible reason and solutions.

Reason 1: When you create an Ad unit, you choose to show a solid color when AdSense cannot find a match content on the page. And the solid color you picked is the same as the background color on the problem area.  
Solution 1: Most of time this is not a case. If it does, then try to used a different solid color.

Reason 2: You just created/updated an Ad unit, which usually take up to 10 minute to load
Solution 2: Wait 10 minutes to see it works or not

Reason 3: The AdSense code does not correctly paste. You cannot write the code in a single line.
Solution 3:

The is happen to me, see the code below,

//a sinlge line below causes a problem
<script type="text/javascript"><!-- google_ad_client = "pub-xxx"; /* 160x600, created 3/4/09 */ google_ad_slot = "9031182928"; google_ad_width = 160; google_ad_height = 600; //--> </script> 

After changed it like below, it fixed the problem.

<script type="text/javascript"><!-- 
google_ad_client = "pub-xxx";
 /* 160x600, created 3/4/09 */
 google_ad_slot = "9031182928";
 google_ad_width = 160; 
 google_ad_height = 600;
 //--> 
 </script>

2009/03/05

Mark all gmails as read

I use Outlook to revieve emails a lot. Sometimes, especially I'm at work, I also logon my Gmail thru Firefox. I installed the Google toolbar for firefox with Gmail notifier to let me know when a new email coming in.
Here is a problem, using Outlook to recieve emails, the received emails in you account are still shown as unread. So Gmail notifier keep on indicating there are new emails when I restart the firefox, but acutally, they are not really new. So I decided to mark those emails as read, however, it's painful if you have tons of emails unread. 
Google is always my best friend, I found a solution at http://www.woodwardweb.com/technology/marking_all_mai.html   
To mark all mail as read:-
   1. In the search box, type "is:unread"
   2. In the select area press "All"
   3. A link will appear that says "Select all conversations that match this search", press it
   4. From the drop down, select "Mark All as Read".

2009/03/03

Apache built-in funtion, server-status

There is mod_status built into Apache web server to get server status from web browser. With this module you can easily find out how well your server is performing.
You can turn in on in httpd.conf file, like below,
<Location /server-status>
    SetHandler server-status
    AuthType Basic
    AuthName "Admin Area"
    AuthUserFile /var/www/passwd/passwords
    Require user admin
    Order deny,allow
    Deny from all
    Allow from 172.16
    Satisfy any
</Location>
All reports are generated in a html format. You can easily find out following type of information:
   1. Total number of worker serving requests
   2. Total number of of idle worker
   3. Find the status of each worker, the number of requests that worker has performed and the total number of bytes served by the worker
   4. Total number byte count served
   5. Other information such as CPU usage, number of requests per second,current hosts and requests being processed etc.
For example, you may see 1&2 like below,
233 requests currently being processed, 13 idle workers
Here, 233 is simultaneously running requests, which cannot access the maximum number you set up. Depend on how busy your server is, you may make this number bigger. The default number is 256.
Usually, you can set this in your http.conf file, like below,
<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      512
MaxClients       512
MaxRequestsPerChild  4000
</IfModule>