01.12.08

Windows Live Messenger won’t open? Here is the solution! Sorta..

Posted in Programming at by chenty

One of my friend called me two months ago because he could not open his MSN Messenger. When he double click the MSN icon, it was simply no response. However, MSN process was shown in Task Manager. I tried to reinstall the program but the problem persisted. A couple of days later my friend called me and told me his MSN suddenly worked again!

Yesterday, I got hit by the exact same problem. No matter what I tried, my Windows Live Messenger would not open. After googling around, I found this post:
http://forums.microsoft.com/msdn/showpost.aspx?postid=1553517&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=0

It seems that Windows Live Messenger has some conflicts with D-Link Router, so the router blocked the Messenger, and the Messenger will stall and try to connect the server forever. If you disconnect the Internet, the program will open immediately.

Solution: Reset your router! Well, you do NOT have to reset the factory default and lose all your settings. A simple reboot or unplug the power for 15 seconds will do the trick. People report that the problem does come back once in a while, alas! Fortunately, “Once in a while” means “once in a few months” in this case.

10.15.07

Install PHP + MySQL on Windows 2003 (IIS + PHP + MySQL)

Posted in Programming at by chenty

1. Why Windows Server 2003 and IIS?
The optimal environment for running PHP + MySQL application is a Linux server running Apache Web Server. It requires minimal setup and assures the best performance and reliability. However, what if .NET applications are required to run on the same server? I guess the only option is to install PHP + MySQL on a windows server (Why not .NET on Linux? No, the other way has been tried, but it did not work well).

On a windows server, Apache Web Server is still the best choice to run PHP + MySQL combo, but unfortunately Apache and IIS cannot share the same port, which means only one of them will run on port 80 (even you bind 100 IP addresses on the same server). Therefore, if you want to run both PHP and .NET applications on the same server, your best bet will be IIS + PHP + MySQL.

2. Sample environment
(1) Windows Server 2003 SP2 + IIS 6.0
(2) PHP 5.2.4
(3) MySQL 5.1.22

3. Download Files
(1) PHP: http://www.php.net/downloads.php
There are several PHP packages for Windows. Make sure you download “Zip Package”. DO NOT DOWNLOAD “installer”! Too many people have problems with “installer” version and that package messes up too much.

(2) MySQL: http://dev.mysql.com/downloads/
As the time I wrote this guide, MySQL 6.0 is out as a public preview. I did not use it because there is no manual. I recommend to use a stable release for production servers.

4. Install MySQL
(1) Most tutorials online installs as the order: MySQL -> Apache -> PHP because you can test MySQL alone, and when you install PHP you can directly modify php.ini for MySQL (otherwise, you have to modify php.ini again after you install MySQL).

(2) I downloaded installer version of MySQL. Just run setup.exe and it will do all the work for you. I am lazy to write detail installation process because I have not had any problem. Everything was straight forward. If you had run in a problem, check official documentation:
http://dev.mysql.com/doc/refman/5.1/en/installing.html

(3) Test MySQL server in command-line:
a) Start -> Run -> cmd
b) mysql -u root -p
c) input your password
d) if it connects to the server successfully, you are in good shape. type “show databases;” to display all default databases. If you see the list, you are ready to move on.

5. Install PHP
(1) Unzip all the files to “C:\php” (I unzipped to “C:\Program Files\PHP” but I have seen people having problem with file path that contains “space”, so most tutorial uses “C:\php”.

(2) create a folder you want to run PHP applications, e.g. C:\inetpub\phproot. Most tutorial uses “wwwroot” which is the default IIS web directory, but I think it makes sense to use a different directory since I don’t want my application mess up with all asp files.

(3) Modify php.ini
php.ini is the most important configuration file. I will revisit this file later in this guide when I talk about setting up email and file upload. For now, we need to modify:
a) “doc_root”: set this as “c:\inetpub\phproot”;
b) “extension_dir”: set this as “c:\php\ext”;
c) uncomment lines with mysql extensions (e.g. remove “;” before “extension=php_mysql.dll”);
d) change default exection timeout, e.g. “max_execution_time = 3600″ (Note: this is very important! I have rarely seen tutorial mentioning this parameter, but the default is 30 seconds. If you did not increase this number you will get way too many 500 error and take you forever to figure out “what’s wrong with my code?” (there is nothing wrong with your code, but the server will return an error after 30 seconds).

(4) Setup IIS (using “IIS Services Manager”):
a) expand “Web Service Extensions”;
b) Action -> add a new service extension;
c) enter “PHP” as name and click “Add…”, and select “c:\php\php5isapi.dll”. (Note: many earlier tutorials recommend to use CGI mode because ISAPI is not stable for PHP. I believe things have been improved dramatically now and most new tutorials prefer ISAPI to CGI);
d) Create a new website. Set “c:\inetpub\phproot” as home directory;
e) In the same “Home Directory” tab, click “Configuration…”;
f) In the new dialog window, click “Add…”;
g) Set “c:\php\php5isapi.dll” as executable and “.php” as extension. Make sure “Script engine” option is checked.
h) Now restart your IIS Server (open “Services” in Control Panel, and restart “World Wide Web Publishing Service”)

(5) Run a test script for php setting:
Create a new file in “c:\inetpub\phproot” and name it “test.php”. Open it with notepad and type:

  1. < ?php
  2. ?>

Run this script, e.g. type “http://localhost/test.php” in a web browser. If you see the script display a whole page of server configuration like this one, that means your server is supporting PHP now. Scroll down a little bit in the page, and make sure it has sections for “mysql” (In the sample I provided above, it has a section for mysql).

Note: If you did not get the expected result unfortunately, there are many good posts on troubleshooting. Troubleshooting is beyond the scope of my guide.

============================================

Now you got a good server running PHP + MySQL under IIS, and most tutorial will stop here. However, it is far from over for a production server! In my case, the application I run requires:
(1) backward compatibility of old instruction sepraration;
(2) sending email using mail();
(3) users can upload files.

If you just follow my guide above, non of these features will function properly!

(1) Proper instruction separation for PHP should use “< ?php" as open tag and "?>” as close tag. However, many legacy code has other format, e.g. “< ?" to open and "?>” to close. The best practice is to modify the code for standard format! Nonetheless, PHP can still support “< ?" opening by set "short_open_tag=1" in php.ini.

(2) PHP supports file upload from client to server, but PHP file upload feature is not enabled under IIS by default.

You need setup two folders on your server. One is the folder where you want the upload files to store, and the other one is the folder for temporary upload files (PHP handles upload in two separate steps: it first uploads the file to the temp folder, and then use "move_uploaded_file()" function to move from temp folder to final destination. For a good example, check official doc http://ca3.php.net/features.file-upload).

Here is an example on setup procedures:
a) create two folders "c:\inetpub\phproot\uploads" and "c:\inetpub\phproot\upload_temp";
b) In "IIS Service Manager", right click on the folder and click "Properties". In "Directory" tab, make sure you enable "write" permission for both folders;
c) Open php.ini, uncomment and edit this line: upload_tmp_dir = "C:\inetpub\phproot\upload_temp\";
d) restart the service and file upload feature should be enabled.

(3) If you google "php mail IIS", you find many many posts from people who have trouble to make mail() function work. I have talked about this issue in another guide I wrote.

10.09.07

How to make PHP mail () function work on Windows

Posted in Programming at by chenty

mail() is a useful and powerful function in PHP, but many developers got problems to make mail() work properly on Windows. Many these problems were related to headers and different line feed formats between Windows and Linux. However, this post does not address these problems. The problem I encountered last week was how to make mail() function to send even the simplest mail on Windows.

The server setup:
Windows Server 2003 Standard Edition (SP2)
Apache 2.2
PHP 5.2.4
MySQL 5.1

run a test script with phpinfo() to confirm the server settings. There were several lines that relate to mail():
smtp = localhost
smtp_port = 25
sendmail_from = yourname@yourdomain.com
sendmail_path =

Windows and Linux handle mail() differently. Linux uses “sendmail” whereas Windows employs SMTP. You can refer to PHP manual for more information:
http://ca3.php.net/function.mail

In this post, I will only cover Windows. Windows Server 2003 comes with IIS 6.0, which supports SMTP. If you are a .NET programmer, you will find mail features working out of box. Unfortunately, this was not the case for PHP. You can try to run the following script to check if mail() works:

  1. if(mail(‘test@test.com’,‘test subject’,‘test message’))
  2. {
  3.   echo(‘ok’);
  4. }
  5. else
  6. {
  7.   echo(‘not ok’);
  8. }

If the script returns ‘not ok’ when you run the code, that means mail() function could not send the mail through SMTP. So what was the problem? A good way to demonstrate the problem is run an email client (e.g. Outlook Express) and setup a new account using “localhost” as SMTP. When you try to send a new message, you will receive an error similar to this one:

Server Response: ‘550 5.7.1 Unable to relay for yourname@yourdomain.com’, Port: 25, Secure(SSL): No, Server Error: 5500

This is the reason your PHP script cannot send the mail: by default, IIS restricts all SMTP relay! In order to solve the problems, you need to grant access to your server IP:
1. Open “IIS Manager”;
2. Right click “Default SMTP Virtual Server” and select “Properties”;
3. In “Access” Tab, click “Relay…”;
4. Check “only the list below” and click “Add” to add the server IP.

Now, if you open Outlook Express and create a new message, the mail will be sent out properly. Now, run the test script I wrote above, the script should return ‘ok’ and you should receive the mail in your mailbox amazingly!

08.31.07

Silicon Valley interview questions?

Posted in Programming at by chenty

This is not the first time I read news articles about tough questions interviewees were asked during an interview for top companies such as Google. My favorite one is “why are the sewer lids round in shape instead of square”?

I have always questioned about the effectiveness of those questions, especially from my “bad” experience. I once attended an interview from Microsoft, and the interview went very well at the beginning. Suddenly, I was asked if I were the product manager, how could I design a remote control for senior people.

My answer was: if I were the manager I would like to conduct a full survey of seniors first, and ask for what difficulties they have when they use a remote control. The manager was very disappointed with my answer, and he started lecturing me about what suggestions I should have give. He named a long list of features he think it would be “cool” for seniors. I did not want to argue during the interview, but all I had in my mind was: if I were the manager, I need to make sure the product addressing the need not just to be “cool”. The real question is: will seniors really spend hard earned dollars for a universal remote control? I believe simplicity is over functionality in this perticular case. Apparently my performance didn’t impress the manager and he cut short with my interview immediately. When I got home, I googled the interviewer’s name and surprisingly learned that he was actually the team lead for Outlook 97 and Outlook 2002. Any thoughts of that? :-)

Nonetheless, I still like to read and solve these interesting interview questions as brain teasers, but I deeply doubt the usefulness in an interview since if you cannot press the “hot button” you will be judged unfairly. On one hand it helps to pick up smart thinkers, on the other hand it filtered out deep thinker.

The question I read today is “how much money will you make if you clean all windows in Seattle”? The author has suggested the following answer:

assume 10000 buildings in Seattle; 600 windows per building; 5 mins per window; $20 per hour wage; the income will be $10 million

I think this answer is kinda boring, so I tried some other approaches:

(1) If I were granted a contract to clean all windows in Seattle, I would become a monopoly. So I can charge whatever price and maximize the economic rent as long as consumers can afford, which means I can make way more than $10 mil! More importantly, if I could subcontracted the work, I could make money sooner.

(2) Think about time value of money! Sure, you can finish all windows and make $10 mil. However, to finish all windows it took more than 57 years if I did it non-stop, 24X7. If I worked as normal, I could not even finish the work in my life. Therefore, this income stream becomes a “perpetuity”. Assume I worked 8 hours a day, $20 hours per hour, 200 days per year, my annual income would be $36,000 and assume my expected rate of return is 5%, the present value of my total income would be $36000/0.05 = $720,000, which is way less than $10 mil.

Things can get even more complicated if you combine the idea (1) and idea (2). Happy brain teasing! :-)

08.20.07

Text file splitter by number of lines

Posted in Programming at by chenty

I have not updated my blog for almost seven months. The main reason is that I am making some big move! I am getting into finance! I have been preparing my Charted Financial Analyst exams for months.

Anyway, I need to write about CFA in another post, so I’d better talk about text file splitter. I have a very simple need, split a big text file that is over 1GB into small pieces so I can only them with text editors. My first take is to download some freeware, but I was out of luck, and people charge $10-$30 USD for such a simple task! Jeez. I have found some free chinese file splitter, but they all crash upon opening the file. The reason they crush because they all load the whole text file for preview first, which does not make any sense imho.

I have found some source code online but most of them advertised as “untested”, so I decided not to read them. After spending hours of researching and having tried more than 20 software, I decided to write my own.

You can download the app here (no need to install, just run it as long as your computer has .NET 2.0 installed):
Text File Splitter By Number of Lines (binary)

You can download my C# source code (VS2005 sln) at:
Text File Splitter By Number of Lines (source code)
(I was in a rush, so I mistakenly named my app as “text splitters”. Please forgive my grammatic mistake.) :)

I have not implemented a good checking mechanism such as using “try…catch…” because I only have one file to split. The speed is not bad: I have splitted a large text file (250MB) into 302 files (each has 10,000 lines) in just one minute.

My code is absolutely free (well, it only takes me less than an hour to create this, so I don’t think I deserve $10). :)

If this app works for you, please link to my app on your blog so more people can use it without paying (saddly, those who charge for this have very good google ranking) .

01.23.07

Installing slmodem driver on Fedora Core 6

Posted in Programming at by chenty

A legacy program we have requires to use a modem to dial-up. The modem is Diamond SupraMax LE internal PCI modem, and the oprating system is Fedora Core 6. Because the modem is using a SmartLink chip, my initial try was to build slmodem downloaded from:

http://linmodems.technion.ac.il/packages/smartlink/slmodem-2.9.11-20061021.tar.gz

Note: For newest Smartlink linmodem driver, you can go to: http://linmodems.technion.ac.il/packages/smartlink/

Unfortuantely, when I was trying to build the package (”make”), it returns an error about unknown “config.h” file in the kernel. After searching around, I found a slmodem-alsa RPM (search slmodem from rpmfind.net). There is a rpm package for Fedora Core 6 and I have no problem installing the package. However, for some reason the package does not work. When I try to start the daemon, it gives me an error. After a whole afternoon’s trial and error, I almost gave up and was ready to try another modem. Then I find this article:

http://www20.brinkster.com/olivares/slmodemd-setup-1.html

This article addresses the problem with missing config.h, and it guides you step by step to modify Makefile and build the slmodem-2.9.11 source code.

The brief steps are:
1. download 2 files from here. You will need slmodem-2.9.11-XXXX.tar.gz (XXXX is the latest date) and ungrab-winmodem.tar.gz
2. extract both tarballs
3. comment out the lines with config.h in /slmodem-2.9.11-20061021/drivers/amrmo_init.c and /ungrab-winmodem/ungrab-winmodem.c
4. add as a single line to /etc/modprobe.conf:
install slamr modprobe –ignore-install ungrab-winmodem ; modprobe –ignore-install slamr; test -e /dev/slamr0 || (/bin/mknod -m 660 /dev/slamr0 c 242 0 2>/dev/null && chgrp uucp /dev/slamr0)
5. copy /scripts/slmodemd from source code folder to /etc/rc.d/init.d/, and “chmod +x slmodemd”
6. modprobe ungrab-winmodem and slamr in slmodemd file
trick: search for “start()” and add these two lines below right after “start() {”
modprobe ungrab-winmodem
modprobe slamr
7. do chkconfig (seriously, I am not a Linux person, and I am not sure what’s this for, but it makes my build successful)
[root@localhost init.d]# chkconfig slmodemd –add
[root@localhost init.d]# chkconfig slmodemd on
[root@localhost init.d]# cd ..
[root@localhost rc.d]# for i in 0 1 2 3 4 5 6
> do
> ls rc$i.d/*slmodemd*
> done
rc0.d/K10slmodemd
rc1.d/K10slmodemd
rc2.d/S90slmodemd
rc3.d/S90slmodemd
rc4.d/S90slmodemd
rc5.d/S90slmodemd
rc6.d/K10slmodemd
[root@localhost rc.d]#

[root@localhost rc.d]# chkconfig slmodemd –list
slmodemd 0:off 1:off 2:on 3:on 4:on
5:on 6:off
[root@localhost rc.d]#
8. now you can “make” and “make install” for both packages.

The instruction I listed is just a brief ones, and I really recommend you check the original post and follow their instrustions. I take no credit for their good work at all! I need to thank them for make my modem works. :-)

12.28.06

Earthquake knocks out Internet in Asia - Follow up

Posted in Programming at by chenty

I just got an interesting screenshot from InternetTrafficReport.com (ITR)

The ITR index for China has been bounced between 10 and 30 for the past few days. I was lucky to get a “0″ this morning.

Well, I hope everything get back soon.

link: http://www.internettrafficreport.com/asia.htm

Screenshot:
Internet Traffic Report Screenshot

Earthquake knocks out Internet in Asia

Posted in Programming at by chenty

I am visiting Chinese website daily and found all website suddenly stopped working on Sunday. I tried to reset routers, servers and computers but nothing helped. I had no problem to connect websites in North America. This reminds me what happened years ago when a fishing vessel accidentally damaged one of the fibre optic cables connecting Internet between North America and Asia.

However, this time is even worse! In the next several hours, I learned that there was an earthquake near Taiwan has damaged some backbone cables, and later on it is reported that all 6 main cables have been damaged. 4 of them had been complete disconnected and the other 2 were merely partially working.

Most telecom companies have rent satellite channels, private cable operator or some bandwidth routing through Europe. However, it has been 4 days, and I couldn’t connect websites in China properly still. Some websites may work but need to repeatly refresh.

It takes 2 weeks to repair undersea cables in average. To fix all 6, it might take longer than that. What a mess!

11.19.06

How to connect a share folder in domain from a computer that is not in domain.

Posted in Programming at by chenty

I use my laptop in different places and they all have different domains. I don’t want to login my computer with different user name for each individual domain, so I just login my local computer. However, when I am trying to connect a share folder that within the domain, it will tell me “Access is denied”. It will not prompt for user name or password, but simply use my current local account info.

There are many ways to around this problem. One way is to create a user name within the domain which has idential user name and password with your local account. I did not try that, and I found that is not feasible most time.

My solution is to use Map Network Drive:

1. Right click-on the folder you want to connect through “My Network Places”, and choose “Map Network Drive…”
2. Click on “Connect using a different user name”
3. The user name should be in something like “ABCCompany\Bob” format (ABCCompany is the domain name, and Bob is the domain user name that has privilege to connect to the folder”, and type corresponding password as well. Now click “OK”.
4. Click “Finish”

This sounds simple, but often you will get an error message:
The network folder specified is currently mapped using a different user name and password. To connect using a different user name and password, first disconnect any existing mappings to this network share.

and,

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again…

This happens because you earlier trying to connect the computer with your local account info. You must disconnect this connection before you can try to connect with a different account, i.e. a domain user

To do this, go Start -> Run, and type “cmd” to open a DOS window (sorry, that is how I call it…)
type the command:
net use * /delete

now you can disconnect all existing connection, and you can map a Network Drive as I metioned above. ;-)

10.13.06

Blog Server Has Been Moved

Posted in Miscellaneous at by chenty

I just moved my blog to a new hosting company, HostMySite.com. I already have several other websites hosted there for almost 2 years, and their service is really good. :)

I also separate IT category from Programming category because I plan to write more about IT industry. There are many interesting things going on due to recent Web 2.0 frenzy.

« Previous entries ·