Array comparison in PHP

While working on a recent project, I had to do some array comparison. I did array comparison by doing the following:

According to my requirements the above two arrays are same but if we compare it in PHP, it would not think so due to the presence of value on different indexes. To solve that, I first sorted and then compared these arrays, which gave me the required result.

Incremental backup using Rdiff-Backup

Backup. No one can deny the fact that it is a very core requirement of IT businesses. We had been using a script to backup data to a specified folder on our Linux server and then from Linux server we used to write CD weekly or bi weekly basis. Due to lack of time, we couldn’t improve this for quite sometime.

Recently, when due to some extremely busy schedule I couldn’t take backups on CDs, I thought to improve our backup process. Our requirements were really simple, we needed a backup process which could copy our required folders to a remote server and then later on keep doing some incremental backups there. Upon some research, I found two software being used for this purpose one is rsync, the other one rdiff-backup, I chose to go with rdiff-backup software as it was purely written for this purpose of backup and it also uses the libraries of rsync.

I studied and evaluated it and found it worth trying. After a few days of trying on this on my local machine, I installed this both on our local server and online server to start backup using this. Following are some of the steps which would help anyone setup this on their machines:

  • To use rdiff-backup for remote backup of local servers. Both servers need to have rdiff-backup installed. rdiff-backup is available from apt-get on a debian system and for Redhat based systems it could be downloaded from
  • After installing rdiff-backup on both servers to start taking backup issue the following command:
    rdiff-backup /home/www/ [email protected]::/home/meraj/backup/ (whhere /home/www/ is my local source folder to taken backup of and [email protected]::/home/meraj/backup/ is server address and destination folder)

Now my next step is to automate this stuff. I don’t want do this every day manually so now will try to get some time and automate this by writing a shell script and then run it through crontab.

While setting up and running rdiff-backup, I noticed the following issues:

  1. To make sure that rdiff-backup is working correctly, before trying to start backup run ‘rdiff-backup –version‘ on both servers and make sure that it returns version correctly, which would mean that rdiff-backup is correctly configured and running.
  2. Make sure that on the destination server we have SE (on redhat machines) not running or if running, then make it permissive mode.
  3. In case running SE in permissive mode also doesn’t help then try to relabel the _librsync.s using ‘chcon -t texrel_shlib_t /usr/lib/python2.4/site-packages/rdiff_backup/_librsync.s

Rakaposhi Base Camp Trek

I have done the following trek last year so if any one needs more information, then please comment below.

Rakaposhi Peak
Rakaposhi Peak

  • Day 1 – Saturday 21st June 08: Start from Lahore at early in the morning from Daewoo Bus and reach at Pindi at 1:00 PM and go to Peer Vedai Bus Stand and get the seats of NATCO Ac and at 4:00 Pm bus will start for Gilgit
  • Day 2 – Sunday 22nd June 08: Reach Gilgit in the morning and immediately get seated for MINAPIN so that we will reach MINAPIN. It takes almost 3 to 4 hrs from Gilgit to MINAPIN. At MINAPIN we will try to stay at DIRAN Guest House or we will camp at the campsite of DIRAN Guest House. So that is the day we will have to search for a Guide, Porters + Donckey & a Cooker.
  • Day 3 – Monday 23rd June 08: Today is our 1st day to Trek by foot from MINAPIN to HAPAKUN 3 ~ 4 Hours, 5.8km, 792m ascent (See Detail + Map & camp at night at HAPAKUN
  • Day 4 – Tuesday 24th June 08: Today our destination is HAPAKUN to TAGAPHARI 2 ~ 3 Hours, 3km, 457m ascent
    View of Rakaposhi from Tagaphari
    View of Rakaposhi from Tagaphari

    (See Detail + Map) & Camp at TAGAPHARI.

  • Day 5 – Wednesday 25th June 08: At TAGAPHARI we will see our health + body condition & decide that will we go to KACHELI LAKE (See Detail + Map) OR Way back to MIAPIN via GUTUMERUNG & ASKORESHUNG (See Detail + Map).

If we decided to go to KACHELI LAKE then we will Trek on 5th Day to KACHELI LAKE via DIRAN BASE CAMP and stay night at KACHELI LAKE.

  • Day 6 – Thursday 26th June 08: Today we will try to come back to HAPAKUN via TAGAPHARI.
  • Day 7 – Friday 27th June 08: Today we will try to reach GILGIT via MINAPIN.


If we decided to go to GUTUMERUNG & ASKORESHUNG then on 5th day we can see both places in a day and at night camp atHAPAKUN.

Deran Peak with Rakaposhi massif
Deran Peak with Rakaposhi massif
  • Day 6 – Thursday 26th June 08: Today we will try to come back to MINAPIN & do rest a night at Diran Guest House.
  • Day 7 – Friday 27th June 08: Get a van early in the morning for GILGIT & do shopping at Gilgit whatever you like and try to get the seats for Pindi at NATCO.
  • Day 8 – Saturday 28th June 08: Reach INSHA ALLAH at Pindi and get the seats for Lahore and at night we will be at Lahore & Sunday will be for a rest day for you to start to go to office on Monday and live in the memories + dreams of this Trek for a year and next year INSHA ALLA for our program will be of K – 2 Base Camp.


Camping at Rakaposhi base camp
Camping at Rakaposhi base camp

So brother this is the plan, but it is an ideal plan. I haven’t counted for certain uncertainties like

  • Weather factor, landslide
  • Health problem
  • May be Trek is more tough than we think so then we shall have to add at least a day for trekking.

Following is the list of things that each person has to bring along:

View of Rakaposhi from Tagaphari
View of Rakaposhi from Tagaphari
  • Hiking bag (must be reliable and shoulder strips must be strong enough)
  • Sleeping bag (preferably light weight but more warm)
  • Shoes preferably like army shoes or something that have designed pattern in its sole so to facilitate walking on slopes and snow. Slipper must also be taken along because after a tough trekking in the day, u needs to relax your feet after reaching the camping place. You cannot wear long shoes all the time.
  • Sunglasses are also very necessary item. because there is immense sunshine around glaciers that can have adverse effect on eyes.
  • Personal things like shaving kit, towel, spare under garments, spare socks etc
  • Other optional things may include camera, Walkman, note book (for taking some notes), torch etc.

Now I am noting down the things which we need to take as a group (you don’t have to worry about these as we will share them)

  • Tent: I have a tent for 6 persons.
  • Eatable items; Although I hope that in that season we can have some help from summer settlements all along the trek, but we shall keep our ration in any case). I shall buy tinned food and some dry ration like biscuits etc from Karachi / Lahore so please tell me that what will you like to eat & can I buy all from Karachi or at Lahore with you people.
  • Milk powder, tea bags, coffee, sugar, egg powder, corn flake.
  • Noodles, Taftans
  • Certain other instantly cooks able things like Haleem in Tin, Fish in Tin, Beans in Tin, Biryani in Tin.
  • Packets of something like TANGS, Toffees, Pineapples Tins.
  • Utensils: we shall buy some (2 or 3) aluminum bowls for heating water which shall be used for tea, noodles as well as for warming tinned food. Anther things include plates, spoons, disposable or plastic cups etc.
  • Medicines, mosquito repellent, desprine, panadol.


Clear View of Diran Peak in the morning
Clear View of Diran Peak in the morning

The estimated cost of our trip is about rs.10000/head. It is from Lahore to Lahore and include:

  • Bus fare from Lahore to Pindi & Pindi to Gilgit and back.
  • All meals plus food items purchasing
  • Charges of guide and porters.
  • Expenditure of hotel (if any night spent)
  • I must mention that these are not the charges like travel agencies that you have to pay. You will see we shall have a transparent accounting of all the expenditure daily. Whatever will be the expenses shall be equally shared by all of us. Rs.10000/head are the roughly estimated charges, as we don’t know rates of many things. So safely we must carry some extra money with us. There may be chance that if we get porters / guide at lesser rates, the overall charges drop to 8000/- but nothing can be said at this stage.


  • Duration 3 ~ 4 Days
  • Distance 17.6 km
  • Standard Easy

It’s four stages total round trip from

  3. tow stages to return via the same route.

MINAPIN’s ground zero is DIRAN Guest House. The gracious hosts, well prepared food and peaceful grassy compound with orchard – shaded gardens distinguish this as one of the Northern Area’s most tranquil places to stay. The dorm cost Rs. 70, and single/doubles cost Rs.400/600, all with hot running water. The camping fee is Rs. 100. If you need a place to really rest and hang out for a few days between treks, this is it. It also rent tents, sleeping bags and kitchen equipment and sell limited food but it’s advisable to bring all trek food and supplies from GILGIT or KARIMABAD.
Public vans to PISAN and MINAPIN depart GILGIT’s Khazana (Bank) Rd new Golden Peak Inn, usually between 1and 2pm. they’re unmarked and can be hard to find. The three-hour ride cost Rs.50, plus Rs 10 per backpack or duffel bag. The 4km long road to MINAPIN leaves the KKH at PISAN, just east of GHULMET. From PISAN, it takes 45 minutes to walk to MINAPIN. The same public vans depart PISAN and MINAPIN daily for GILGIT at 6.15am.

When the MINAPIN vans are full, try PISAN and MIACHAR vans. The PISAN vans depart GILGIT before the MINAPIN vans, usually between noon and 1pm. The MIACHAR vans depart GILGIT about an hour after the MINAPIN vans. GILGIT – bound MIACHAR vans pass the DIRAN Guest House about 7am, but are usually already full.

No direct transport links MINAPIN with KARIMABAD, so just get to the KKH and jump on any passing vehicle. KARIMABAD – MINAPIN special hires cost Rs.1000.


  • 3 ~ 4 Hours, 5.8km, 792m ascent

From DIRAN Guest House (2012m), follow the road two minutes east. Then turn south (right) onto a dirt lane and follow it five minutes to the canal along the village’s south end. Turn west (right) and follow the path along the canal 15 minutes towards the MINAPIN River. Walnut trees shade the path and provide a home for nesting orioles (MAIUN). The trail turns south into the canyon and crosses a footbridge (2103m) over the rushing to the river’s true left bank after 10 minutes.

The trail rises 183m on switchbacks for 30 minutes then eases of and enters an open, aromatic juniper forest. Continues along the broad, shaded trail, rising gradually in one to 1 ½ hours to the huts at Bang – i – das, long a clear stream that tumble over a cascade at the head of this pleasant side valley. The trail follows the stream 30 minutes to the base of waterfall, where it forks. The right fork, which crosses the stream over a footbridge, leads to GUTUMERUNG (alternate route). Follow the smaller left fork and climb 90m in 15 minutes to the grassy, tiered meadows of HAPAKUN (2804m) bordered by stands of mature fir trees. The BURUSHASKI name HAPAKUN is given to a place (kun) within a day walk of a main village, which is defined as ‘close enough to carry child’ (HAPA).

Camping is free in the open meadows, with northern views of HACHINDAR and MAIUN Peaks above the HUNZA River. DIRAN and RAKAPOSHI remain hidden from view. Ibex inhabit the steep cliffs to the east high above MINAPIN Glacier. A small, sometimes silty stream flows near the herder’s huts HAPAKUN, but a clear spring lies behind and five minutes below the huts. It cost Rs.40 – 50 to camp on private land near the spring.

  • 2 ~ 3 Hours, 3km, 457m ascent

Crossing the canal between the two huts, the trail (the one perpendicular to the canal, not parallel to it) heads south, rising across rock-strewn open ground beyond HAPAKUN’s largest hut – for a minute or two – and then climbs immediately west up dusty switchbacks through fir forest for 14 minutes. The trail eases off and contours the rocky slopes foe 30 minutes to a verdant bowl where wildflowers and colorful songbirds thrive. Sweeping gently through the meadows, the trail enters scattered juniper stands and climb switchbacks to the windy ridge top, where DIRAN, RAKAPOSHI and their interconnecting ice wall finally come into full view.

The trail thins and traverses a rocky cliff above the spectacularly broken MINAPIN Glacier 15 minutes to TAGAPHARI (3261m). Once a muddy (TAGA) lake (PHARI), as its BURUSHASKI name indicates, it’s now a level pastures where cows and oxen graze. A herder’s hut is next to the rocky hillside, with plenty of good grassy campsites along the meandering stream. A small seasonal spring lies at the base of rocky slope towards the head of this small valley. The lateral moraine above the valley is a fun place to watch avalanches crashing down from the ridge between RAKAPOSHI and DIRAN, and to catch the sunset on DIRAN. RAKAPOSHI itself is mostly hidden from view behind the obvious snow down of RAKAPOSHI Eat (7010m).

  • Side Trip: ASKORESHUNG
  • 3 Hour, 5.8km, 1319m ascents, 1319m descents

ASKORESHUNG (ASKOR means a ‘flower’; SHUNG, a ‘narrow path’) is a view point (3780m) atop the second ridge west of TAGAPHARI from where the BATURA, SHISHPER and ULTER peaks above HUNZA are visible. From TAGAPHARI, ascend steeply west to the first ridge (3650m), descend and cross the intervening GUTUMERUNG stream, reaching the second ridge on two hours. Return to TAGAPHARI in one hour.

  • Side Trip: DIRAN Base Camp
  • 7~8 hours, 12km, 389m ascent, descent

DIRAN base camp is locally known as KACHELI, a BURUSHASKI word meaning ‘the best grazing grass”. MINAPIN and MIACHAR villagers share these birches – dotted pastures. The area, along the MINAPIN Glacier’s north – east margin, is similar to TAGAPHARI with good campsite and a small spring nearby. Visiting KACHELI Lake as a day hike from TAGAPHARI is a more strenuous, but less expansive option than camping at KACHELI and paying porters for two additional stages (one there, one back).

From TAGAPHARI, follow the crest of the lateral moraine south 20 to 30 minutes to the small cairn (3510m) marking the route onto the glacier. It takes three hours to cross the broad MINAPIN Glacier and reach DIRAN Base Camp (3650m). The unmarked route north – east across the glacier’s alternating bands of rock and ice near many Seracs is difficult to follow and changeable, so take a local guide or porter who knows the way. Carry a rope for safety. Watch marginal crevasses when existing the glacier.

From DIRAN Base Camp, trekking south – east up the ablation valley towards the rocky bend (4040m) in the glacier brings you to the point where the route to camp 1 moves onto the glacier, close beneath DIRAN. Enjoy the view, but don’t continue onto the heavily crevassed glacier. Experienced climbers can attempt PHEKER (5465m) from base camp.

  • Side Trip: KACHELI Lake
  • 3 hours, 8km, 300m ascents, 300m descents

It takes two hour to climb steeply to the small KACHELI Lake above DIRAN Base Camp, and half that to return.

  • 3 ~ 3 ½ hours, 8.8km, 1249m descent

Retrace your steps down valley to MINAPIN via HAPAKUN.

  • Alternative Day 3: TAGAPHARI to MINAPIN
  • 4 ~ 4 ½ hours, 8.4 km, 389 ascent, 1639m descent

Ascend the ridge (3650m) immediately west of TAGAPHARI for sweeping views and descend steeply to GUTUMERUNG, a pasture (rung) in this deep (GUTUM) valley where sheep and goats graze. Follow the trail steeply downstream (north) until it passes the waterfall at the head of the Bang – i – Das Valley and joins the rail between HAPAKUN and MINAPIN.

I am sending you the Rakaposhi_Base_Camp_Map so 1st read the Maps at Attachment then 2nd read Plan & then read the above detail information.


  • June is rainy season, so if we come to know about closing of KKH before starting the trip we may have to re-think of our trip.

Rakaposhi Base Camp Map

Mysql backup and delete older files

We were taking mysql backups using a very simple shell script which was using mysqldump as below.

We were keeping old backup files but we knew that we would need to remove the backup files older than two weeks or a month. I was thinking what to do and after some studying I found the following one line, would help us remove files older than x number of days.

Where 15 could be changed to any number of days and it will remove all the files older than that number of days recursively, using this command. This command won’t delete any special files or sub directories.

Testing Tools

For our testing automation and testing environment, some time ago I did some research on the available tools and also evaluated some of them.

I thought, that the tools of list I found during the research (though I didn’t try all of them) would be worth sharing with readers:

I will try to add a small description for each of the testing tool in the above list.

PHP’s empty and isset function

The best way to check if a variable consists any value or is empty is to use empty function from PHP itself.

Though, while coding in PHP it shouldn’t be confused with isset which checks if a variable is set or not set, whether that variable is empty.

Prayers and Hope

I was thinking to write something here but always couldn’t write. I am thinking of many things at the moment and I don’t know if I would be able to implement even one from them.

Let’s pray and hope that I could write a bit reqular here and continue on the projects I have started working on.

I have changed the theme so that it feels a bit fresh on my blog 🙂

Domain Specific Language QA

An interesting question and answers about DSL (Domain Specific Language) with Martin Fowler.

What is a Domain Specific Language?
A Domain Specific Language (DSL) is a computer programming language of limited expressiveness focused on a particular domain. Most languages you hear of are General Purpose Languages, which can handle most things you run into during a software project. Each DSL can only handle one specific aspect of a system.

Read complete question and answers here.