Thursday, May 28, 2009

Timezone: PHP, Shell and Crontab

Programming in different timezones can be a headache if not taken care off initially. Codes written to work in one time zone can go wrong when ported to a server that runs on another Timezone. There a few things to take care off when you change from server to server.

PHP

By default PHP uses the Timezone that is set in the server or php.ini configuration files. Inorder to make a robust php code that can work in any server environment, it is always a good practice to set the Timezone in the code written.

date_default_timezone_set(Timezone)


is the PHP function to set the Timezone in PHP. This can take care of most of the timezone anomalies that can occur in your script when using PHP's Date Function.
Timezone is a string, for example for Indian Standard Time it is "Asia/Calcutta", for LA it is "America/Los_Angeles" etc. Checkout PHP Timezone list for a complete list of timezones.

Shell
In a shell the date command gives you the localtime at the SERVER. In order to set the Timezone to your area, we have to set the appropriate environment variable.

export TZ="/usr/share/zoneinfo/{Continent}/{Place}"
Eg:
export TZ="/usr/share/zoneinfo/Asia/Calcutta"


Add this snippet to your .bashrc to set your timezone to your localtime.

Crontab
Crontab runs in the same timezone as the server, so for now the best thing to do is calculate the offset between the server timezone and your localtime zone, and plan your crontab accordingly.

For example if you are in IST and the server is in GMT, which has an offset of +05:30 from IST, add your cron such that it runs localtime - 05:30 hrs on the server. ie
localtime - (offset time).

It would be easy to write a script to do this for you.

Friday, May 22, 2009

Orkut YouTube Facebook etc Blocked ?? Follow this guide to Unblock

Blocked ??!!!

Most of you may be out there to desparately find out how to unblock all these social networking sites. The solution is to use a proxy. You can use proxy sites available all over the internet, or set up your on SSH proxy if you have an SSH server.

Setting up an SSH server is easy. If you have a machine at home, install any linux distribution with SSH server enabled. Now grab hold of your Home machine IP address and proceed to this page to setup your SSH Proxy.

Alternatively if you don't have the luxury of setting up an SSH machine at home, search on Google "Free Shell Accounts", "Free SSH Accounts", "Free SSH server", etc and sign up with anyone. Beware that your credentials will be passed to these servers while logging in. So it is always secure to use one at your home. Still if you are so desperate, you can do so :D ...

SSH Proxy Setup

Thursday, May 21, 2009

SSH Tunneling Proxy using Putty on Windows and Linux (Unblock YouTube / Orkut / Facebook)

SSH Tunneling?

SSH Tunneling is the method by which, requests from our local system is encapsulated in an SSH session and forwarded to a remote computer, which then sends the requests as if they originated from the remote computer.

Using this method we can set up Socks (V5) Proxies to access websites. This method is used for anonymous browsing as well as for accessing Blocked sites within the local network, such as Orkut, Facebook, YouTube or any other website, you name it :).

On Windows
Setting up an SSH Tunnel on Linux is obvious and I will describe it anyway, but lets see how it is done on Windows first. For Windows you need

  • Putty
  • A Browser

That's about it. Putty is a free software you can download for free.

Next run "Putty.exe", You can see a screen as shown below:



In the Hostname (or IP Address) textbox, provide the IP or Domain of the SSH server. You can get some free SSH servers out there on the internet, try searching for "Free SSH Servers", I am not posting any servers in particular because, I dont see any servers out there that will be there forever. Still there will always be some free servers, Good for us :)...

Next on the left hand side tree, Click on SSH and make sure it appears as in the screen shot below. Watch out for Compression and SSH Version.



Next click on Tunnel Button, and Fill up the source port as 9090 (Can be any port > 1024, Just remember this number, I used 9090) and Click on the Dynamic Option Below, These are highlighted below:



  • After doing these Click the Add Button.
  • Now click on the Tree View on the left side, the top most item, "Session"
  • In Saved Session enter a name and Press Save.
  • Now click Open.

Now a Window should open, and you have to login with your username and password. That's it with the Putty part. :)

Next time you run putty, you just have to double click the saved name from the list of Saved Sessions. No need to follow the above step. Next we have to configure the Browser to use this proxy.

On Linux (Or Cygwin on Windows)
Run the command
ssh -C2qTnN -D 9090 username@remote_machine.com


Setting up the Browser

Firefox
On linux take Edit > Preferences
On Windows take Tools > Options



Click on Advanced > Network Tab > Settings. (Illustrated Above)
Now you get a window as shown below, and fill the settings as shown below.



Manual Proxy Settings
Blank out all other Text Fields
Socks Host: localhost
Port : 9090 (or the one you specified earlier)
Check Socks v5 Option.

Click on Ok and again Ok (in the options Window)

Internet Explorer And Google Chrome
Take Start Menu > Control Panel > Internet Options


Click on Connections Tab > Lan Settings (Highlighted in Figure Above)



Check use a proxy server and click advanced.



Now fill up Socks as localhost, and Port 9090 or the one you gave earlier.
Click Ok and Ok and Ok as needed :)

That's all Enjoy Browsing :)...
Visit "www.orkut.com" "www.facebook.com" and verify that your proxy connection does work..
:)

Saturday, May 9, 2009

Acer Aspire 4520 vs Compaq Presario V3000AU : A wifi comparison

Intro
This is a first hand comparison between the wireless adapter performance between the Compaq Presario V3000/3155AU and an Acer Aspire 4520.

The test

The test I did is to ping the local wireless router / access point.

ping 10.0.0.1 -n 100


These is the result of Acer Aspire

Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
Reply from 10.0.0.1: bytes=32 time=3ms TTL=64
Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
Reply from 10.0.0.1: bytes=32 time=2ms TTL=64
Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
Reply from 10.0.0.1: bytes=32 time=2ms TTL=64
Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
Reply from 10.0.0.1: bytes=32 time=2ms TTL=64

Ping statistics for 10.0.0.1:
Packets: Sent = 100, Received = 100, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 84ms, Average = 2ms


This is the result for Compaq Presario

Reply from 10.0.0.1: bytes=32 time=1424ms TTL=64
Reply from 10.0.0.1: bytes=32 time=16ms TTL=64
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 10.0.0.1: bytes=32 time=2899ms TTL=64
Reply from 10.0.0.1: bytes=32 time=2ms TTL=64
Reply from 10.0.0.1: bytes=32 time=3672ms TTL=64
Reply from 10.0.0.1: bytes=32 time=2ms TTL=64
Reply from 10.0.0.1: bytes=32 time=6ms TTL=64

Ping statistics for 10.0.0.1:
Packets: Sent = 100, Received = 45, Lost = 55 (55% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 4236ms, Average = 801ms


Apparently the connection was too poor in Compaq, I had to use a pen drive to copy the statistics and post it here.

Do you have a Compaq Presario??
Do let me know ...

Tuesday, May 5, 2009

cURL PHP Error on Windows

Fatal error: Call to undefined function curl_init() in D:/webs/php.php on line 284

This problem arises because of not including the lib_curl.dll to PHP. To solve this uncomment the line as shown below

;extension=php_bz2.dll
extension=php_curl.dll
;extension=php_dba.dll


Now restart apache server.
If you get an error "Unable to Load X:/path/php/ext/php_curl.dll", copy
  • SSLEAY32.PHP
  • libEAY32.dll
(OpenSSL) Libraries to the System32 folder.

Now restart apache server and you are good to go.