All posts by Ruturaj Vartak

Scribe PHP logging

I’d put some efforts to make scribed logging work with PHP, what I did was follow python’s example script “scribe_cat”. And made a similar PHP Script out of it, I’d to create many PHP scripts out of n number of .thrift files. Anyways I’ve got a working example. Here it is.

<?php
/*
 * As found on http://highscalability.com/product-scribe-facebooks-scalable-logging-system
        $messages = array();
        $entry = new LogEntry;
        $entry->category = "buckettest";
        $entry->message = "something very interesting happened";
        $messages []= $entry;
        $result = $conn->Log($messages);
*/

$GLOBALS['THRIFT_ROOT'] = './includes';

include_once $GLOBALS['THRIFT_ROOT'] . '/scribe.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/transport/TFramedTransport.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';
//include_once '/usr/local/src/releases/scribe-2.0/src/gen-php/scribe.php';

$msg1['category'] = 'keyword';
$msg1['message'] = "This is some message for the category\n";
$msg2['category'] = 'keyword';
$msg2['message'] = "Some other message for the category\n";
$entry1 = new LogEntry($msg1);
$entry2 = new LogEntry($msg2);
$messages = array($entry1, $entry2);

$socket = new TSocket('localhost', 1464, true);
$transport = new TFramedTransport($socket);
$protocol = new TBinaryProtocol($transport, false, false);
$scribe_client = new scribeClient($protocol, $protocol);

$transport->open();
$scribe_client->Log($messages);
$transport->close();

You can have as many messages or entries into one log, as I’ve demonstrated or tried above, please change the corresponding scribed’s host and port values. I’ve attached a working file and all the required includes generated by scribe. Except for the above script everything is generated by Scribe/Thrift.

PHP, Python Consistent Hashing

I found out the hashing algorithm used in PHP-Memcache is different from that of Python-Memcache. The keys went to different servers as the hash created by python and php were different.

I posted a question on the memcache groups and was lucky to find this wonderful reply.

import memcache
import binascii
m = memcache.Client(['192.168.28.7:11211', '192.168.28.8:11211
', '192.168.28.9:11211'])

def php_hash(key):
    return (binascii.crc32(key) >> 16) & 0x7fff

for i in range(30):
       key = 'key' + str(i)
       a = m.get((php_hash(key), key))
       print i, a

This is the only thing that has to be done on Python’s end, change the way the hash is calculated. The coding on PHP end remains same. All you guys using PHP for web based front-end with MySQL and Python for back-end scripts shall find this helpful.

Thanks Brian Rue.

Reference: http://groups.google.com/group/memcached/msg/7bb75a026c44ec43

Dodital Trek and Uttaranchal: Day 12 & 13 (19, 20 Jun 08)

This entry is part 13 of 13 in the series Himalayan Trip: Dodital Trek and Uttaranchal

Day 12, 19 Jun 08

to Haridwar

5.30 am, Its 5.30 and I cant resist my bowel movement. I need to shit… aagggh!!! my stomach needs an overhaul. By 6.00 Vj’s alarm is ringing, but we decide to cut it off, my head is aching and I don’t feel very healthy, my head is aching a bit, we decide to go back to sleep. Finally around 7.30 we wake up, but it is dark outside, I wonder if its a morning or an evening. Its raining, heavy clouds over the Hrishikesh. We prepare for our ‘check out’. At 9.00am we are at the ashram office, Vj finalizing the details, its raining. I hope it does not rain on the Ram jhulla where we would have no cover to run for. 15 minutes later, ‘Parmarth Niketan’ settlement is over and we move for the Vikram stand on the other side of the river. Things weren’t lucky for us on this trip, and my fear comes true, we were just at the halfway of the bridge and the clouds break lose. The heavy drizzle turns into a torrential downpour. We are left with no option but to run with the big bags till we find ourselves with other fellow tourists under a shop shelter.

 

We wait well over 30 minutes and the rain has gone from bad to worse. Few more minutes and luckily its back to the ‘heavy drizzle’ and we move on. By 10.15am we get a Vikram for Haridwar which is approximately 28kms from Hrishikesh, just a hour plus journey. Around 10.45 and we are in the Motichur forest zone close to Rajaji National park and the rain is now insane. It continues well till the borders of Haridwar. As if heavy bags and wet clothes were not enough, a huge traffic jam at one of the national highway junction is added to our misery. It takes about quarter of a hour for that to clear and we reach ‘Har ki pauri’ by noon.

Haridwar

Noon, We were lucky enough to find a cycle-rickshaw to port us to our local stay at the Gujarati Ashram. The poor fellow waded uphill amongst bustling streets full with cattle, people, cars, pulling around 170kgs of payload just for Rs. 20. At the ashram, luck seemed to be on ourside, when we got a decent room (for a trekking nomad) with an attached toilet/bathroom. We dry ourselves and rest. I’m for sure not feeling normal. Seems like I have temperature. Mallik calls, with bad news, his train is cancelled and now has to fly back to Mumbai. We move out to find food, same old ‘bhojanalayas’ with big fat tandoori rotis and spicy curries, we didn’t want those but weren’t spared. At food, we wondered if we should stick to original plan of the train or book the flight tickets, finally we too decided on shortcut route, flight. We tried to find a cybercafe on the main road, but couldn’t some of the vendors didn’t even understand what we were searching for. Haridwar in this context is quite backward to Hrishikesh, which due to its more foreign influx has somehow kept itself updated. Luckily we find a cafe just close to our lodging. We were lucky to find some tickets vacant for the Mumbai bound flights and book it.

It was almost 4.00pm when we reached back to our room, with nothing to do, we decided to rest. We had planned a evening aarti at Har ki pauri had it been our original plan, but now after booking for a 10.00pm bus to Delhi from Haridwar, that idea was out. My head was still aching and some body was tired, we decide to sleep. 7.00pm, I can’t sleep anymore, perhaps I’m uncomfortable for a sound sleep. In the balcony its cool breezy evening with beautiful colors at the horizon of Haridwar. We click our final snaps of our tour from the balcony of the Gujarati ashram. Go get back on the streets around 7.30pm to have tea and cancel our rail tickets. Vj gets a shave from a local saloon and feels better. By 8.00pm we were packing our bags for the final time, it was more than 12 days back when we had packed our bags for the next day flight for the very first time, wondering how we were gonna make the trek with the 10kg + bags. The chapter was finally on its last few pages.

9.00pm, After checking out of the dharamshala, we were at the travel agent’s shop waiting for a cycle rickshaw to pick us for the bus stand. We wait for almost 30 minutes, getting restless that the travel agent is just not willing to arrange for the cycle rickshaw. Finally he arranges one by 9.30 and we were on our way to the bus stand, in pitch black darkness somewhere around the corner there was a pack of buses, where the fellow asks us to get down, the cycle-rickshaw fellow checks with other fellow who gets a sheet of paper and probably ticked at our bus seat numbers. The bus is full of Gujaratis, Vj jokes he has no respite from them. It feels like being in a bus from Rajkot to Junagarh. Around 10.30 the engine whines and the tyres roll taking us into a new day for the last journey in our trip, back to Mumbai!

Day 13, 20 Jun 08

The seats of the bus are not ‘ergonomic’ a word we really didn’t care at the begining of the trip, but with the last moments with a tired body it made a lot of difference. My neck was aching, the bus stood still, I woke up, the bus was waiting at a restaurant for the tourists to break for food/washroom. It was 2.30am in the morning. After a few minutes its rolling again. I make a head rest out of my wind cheater and luckily have some sound sleep till 4.30, when the conductor of the bus calls for ‘Last Stop, ISBT !’.

That meant we were in Delhi, the bus was circling around some big area lighted with tall lamp posts, somewhere I saw ‘ISBT’. We were circling around the Delhi bus stop, ISBT. Few minutes later the bus stopped and our bags were yet again on our backs, for the last time. There were many auto-rickshaws offering a ride to the airport, with ranges of Rs. 150 – 300. We decided to check at the bus stop. Luck couldn’t favour us more, in front of us we saw slick bus with electronic signboard ‘IGI Airport’

5.00am, The bus moves and we move through the Delhi’s posh and wide roads, circling many government buildings, the Red Fort till we reached the Airport by 5.45. We have some biscuits to soothe our burning stomachs and wait. With us there was group of foreign models probably from Eastern Europe, opposed to us they were very well dressed, with their make ups and energetic. We at the other end were tired, dirty from night long bus ride. I decided to brush my teeth and take a dump at the Airport. Felt a little better, but my body ached, fever for sure, we waited restlessly for our call of ‘Indigo’ flight for Mumbai.

Around 8.30, we checked in our luggage and waited for boarding. By 9.15 we were in the fuselage. As I took my seat my memories returned when all 6 of us were in a similar plane all enthusiastic for the 2 week trip. Around 10.15 the plane took off. We didn’t have much to chat and discuss, both of us tired. As I put my head on the head rest, every single moment of the Dodital trek raced through, Mussoorie, Dehradun, Hrishikesh and all. By 12.15 the plane landed and it took us almost 1.30 before we ventured on the roads in the rickshaw, Vj’s friend came to meet at the airport and I hugged him thanks and all that for the trip and we to split into our own directions. The streets of Mumbai felt familiar but somewhat strange, from the lovely hillocks of the north, crisp clear skies, cool winds and snowy caps, I was back into Cement jungles and tar roads, nevertheless felt very happy to be back Home!!!

Dodital Trek and Uttaranchal: Day 11 (18 Jun 08)

This entry is part 12 of 13 in the series Himalayan Trip: Dodital Trek and Uttaranchal

Day 11, 18 Jun 08

Hrishikesh

7.00 am, In a ‘sleepy’ mode, we are bid goodbye by Mallik. He is still interested in another small trek to Neelkanth. It would be around 2 hrs of a simple trek, but none of us are interested, or rather should I say have the energy. Mallik is still enthusiastic to head back into the woods. I wake almost an hour and half later, a crisp morning in Hrishkesh feels splendid. I wake up Vj and ask him if he is interested in bath at the ghats. Rajo too agrees when I knock at his room. We wait for an hour till Amey and Nikhil get ready to be with us.

The Hrishikesh Ganga is cold as well !! But extremely refreshing. It felt like diving into a river of chilled Soda water, the rich silt brushing, with fizzling cool water running over the skin. Bathing with soap is not allowed so after 15 minutes or later (the sane period we thought would be good enough in the water without troubling our health !) we head back to our rooms for ‘proper baths’.

 

10.00 am, After a clean bath in warmer water we are hungry and wonder about our day’s breakfast. Vj has some Maggi packets left and we decide to prepare it. In a cool religious place, in an ashram you don’t realize how time flies by swiftly. It was almost noon when we finished our ‘breakfast’ and wait for Mallik to come back. Today is our rest day. So nothing more than rest and we are back on our beds.

2.00 pm, Yet again in our sleeps, its Mallik who is waking us up. This time he is coming back from the trek ! We all get back on our bums and listen to Mallik’s experiences about the small trek to Neelkanth. hmm.. this day is good, relaxing, chatting, easing out, one of our first days after the long trek and travelling. TPing.. its almost 4 when we realize we still have to have our lunch. Back on the streets move into the local food-joint trying to search for some appeasing menu item. We all were sick of the paneers, daals and big tandoori rotis. But that was not to leave us yet. After alu sabzi, daal and roti, we roamed in the adjoining street full of travel agents, middle-men, cyber cafes, etc.

Mallik check’s that his train has yet again flip-floped to ‘running’ mode. He has to leave today. Rajo gets home sick and wants to return to Sangli instead of Mumbai. Amey too doesn’t find the trip anymore interesting and wants to leave early. So as tickets get cancelled and booked, me and Vj wonder if sticking to the original plan is the right idea. However we stick to it. Amey and Rajo too are to leave today evening with Mallik and Nikhil. Mallik and Nikhil have got to leave by 7.00 to reach Haridwar for the next days early morning train to Delhi @ 6.00 am. Amey and Rajo book a bus ticket around 9.00 with the cyber cafe / travel agent for Delhi. All of them unknowingly having a flight from Delhi the next day.

6.00 pm, Mallik, me and Vj come back to the ashram. Mallik has to start packing, while others head off for marketing. By 7 Mallik has completed his packing and wondering why hasn’t Nikhil yet come back, who is to leave with him. We three venture out on the banks for the famous Ganga aarti. Over there the scene is captivating, just behind the big Shiva idol, is the west where the sun is setting behind a small hill, its golden rays piercing through the scattered clouds in the blue sky. A golden hue merging into the dark clouds. On the left the temple skyline is lit with a lovely pink/golden tone as the background.

Sunset at hrishikesh
Sunset at hrishikesh
Hrishikesh temple skyline at sunset
Hrishikesh temple skyline at sunset

After capturing the aarti, Mallik decides its time to leave and yet Nikhil hasn’t come back, sticking to military-like plan he leaves us with a hug, the long journey with Mallik on this trip had finally come to an end. We watch him with his backpack till we lose him in the crowds. Around 8pm the trio appears. Nikhil is in a hurry, obviously he has lost the company of resourceful Mallik, and now has to manage on his own. He decides to leave with Rajo and Amey for the Delhi bus and would get down at Haridwar station, unsure, but now his only option. By 8.30pm we are just two of us as even Delhi bus trio leaves. We decide to go back to the Ganga ghat to enjoy the last moments in Hrishikesh’s banks.

9.00 pm, We come back and decide that we cant have more of tandoori rotis, etc. Bread and butter would satisfy us for dinner. I remember I still have my ‘cup noodles’, so thats on the platter as well. We share a laugh the mess reminding us of ‘Mukti’s cousin’. Its almost 10pm and we pack our big bags for yet another journey to Haridwar for the next morning. Its almost after 10 when finally the lights go out for the last time in Hrishikesh.

Kalavantindurg Trek

Kalavantin Durg, the small steep hill adjoining to Prabalgad was our motto of the day, Dec 6, 2008.

With Mallik, his cousin, Raksha, Vj, Rajo, Janki and Neeraj adventured the steep, kindof scary trek.

Kalavantindurg
View the Gallery

Travelling Directions

  • Get to Panvel, Bus or Train (Central Harbour)
  • From Panvel ST Bus Depot, take a bus for Thakurwadi, and get @ the last stop, the base village

Approximate time of Trek: 4-5 hrs (including the return to the base village)
Difficulty: easy to medium, if you are not scared of heights.

Dodital Trek and Uttaranchal: Day 10 (17 Jun 08)

This entry is part 11 of 13 in the series Himalayan Trip: Dodital Trek and Uttaranchal

Day 10, 17 Jun 08

To Dehradun & Mussoorie

5.00 am, I wondered if I’d been here for a vacation or a torture camp, every single day of this vacation I’d been up well before 5.00am. Today’s excuse, ‘Trip to Mussoorie’. We get ready by around 7.00 and cross Ram jhula. A Vikram’s ride leads us to the bus stand. The bus stand was nothing more than a empty ground, with rubbish in corner and a concrete post, where the officials handed over the tickets. We waited there for a Dehradun bus, which took about hour and half or so. All the bus lined up weren’t the ones required. Finally one with Dehradun showed up, a small mini bus. The crowd was bad and we somehow managed to get in. Vj and Mallik couldn’t make in the same bus but another standing by the side. Both these buses left at the same time though around 8 am! The route to Dehradun, the capital of Uttarakhand was good the highway cutting through forests. The roads were decent enough. I was standing most of the time later got a seat just to let off my weight off the legs.

 

Dehradun

9.30 am, We reached Dehradun, got down near a highway crossing. We had to take a vehicle for Mussoorie from the railyway station where the taxis and the bus stand stood. But before we could do all that.. we were HUNGRY. We headed into a sardarji’s dhaba and made ourselves comfortable in an odd half dhaba – half restaurant ambience. We pushed about more than 2 aloo parathas each. While eating we understood that those were half aloo half onion, WHY !? cause the kitchen had made it that way.. We didn’t care! parathaas.. aah! Some of us topped it with a sweet or salty lassi, guys weren’t sure if they got what they ordered. Anyways after the bill we headed towards station. At the station the taxi stands, etc were buzzing with the daily routine. Cab drivers eager to make every tourist his passenger, the careless bus drivers and ‘I care a shit’ attitude of the bus company employees.

After a few economical discussions on a cab-ride or bus ride, we decided on the later and … the crowded one. A Mussoorie bus, rumours came through the crowd that the bus was at the close by junction, and people started to run wildly towards the junction, as the bus approached the area, the conductor just refused to open the doors. We were halfway between running wildly and being civilized.. actually it didn’t really help. Somehow we managed to get into the bus. The bus left around 10 am and took another hour to reach the hills of Mussoorie.

Mussoorie

The ride to Mussoorie was just as wonderful as the name it self. Mussoorie overlooks the doon valley and is at the right top, a hill station ofcourse. The road leading to Mussoorie is a zig-zag winding one, all the way from the base to the town itself. It was raining lightly and the road was glittering. We reached at the Musoorie bus stop aroun 11.15. The bus stop, main bus stop of the town was just big enough to accomodate about 5-8 buses and had a small waiting room. It showed that Mussoorie was probably out of the range for the locals, but for just big industrialists and rich men which was evident from the extremely busy roads jammed with big cars honking in arrogance.

We decided to stroll along the Mall Road and enjoy the lovely climate. The rich and fashionable made their presence felt. Road cleanliness and town maintenance seemed to be the no. 1 priority of township government. There were trash bins all periodically, ad boards of keeping the hill town clean and beautiful. We made sure the lovely road just leaning over the edge overlooking the Doon valley was the place where we had ample of photos. Pressure is building inside my stomach ! The walk led us to the taxi stand where we hired a cab for Kempty water falls around 12.15 pm.

Kempty water falls are about 5-7 km down from Mussoorie, we arrived at the falls locked in a bad traffic jam. Our driver suggested that we move ahead on foot while he’d park the car. Even though being a Tue, a working day it was extremely crowded. All I could see were people. The Kempty water falls are lovely water falls in which the water actually flows over the huge rock faces, not the typical fall in which water comes off from a ridge. So its calm and beautiful. At the base there is an artifical catchment, which creates a pool like effect where people can enjoy. But that causes a lot crowd problems in that specific area. Its still raining. We climb some places for a better view of the falls, and all that leads to uncontrollable pressure. I ask Vj and Mallik to wait at a restaurant, while I can have a dump, I purchase a mineral water bottle! and search for a place/toilet/sulabh shauchaalay. But nothing is to be found, finally I find a place right underneath a hotel which is built on the edges and supported by coloumns wooden and concrete both. I knew this was the place. aaa aahh !! Phew ! I came back washed hands at the same restaurant where all were having their late-late breakfast. And then we headed towards the main fall, the rain has now started to come hard. So we wait near one of the restaurants near the fall, and we decide enough of this crowded nature. We’d seen more beautiful, incomparable vistas on our trek, this was just shit! So we decided to head back to the Cab and leave back for Mussoorie around 2.15pm.

At the Mussoorie bus stop we purchased tickets for Dehradun, and went to a shack for tea. We heard the bus roar behind us.. so we asked the guy…

भैय्या जलदी करना

to which another person responded in a jovial way..

अरे मसुरी आए हो आराम से खाओ पियो !! जलदी क्या है ?

हमारी बस छूत जाएगी…

he replied again..

अरे ऐसे कैसे छूटेगी !

In the bus we knew why that fellow person said so. I happened to be the bus conductor of our bus. As we climbed down the hills around 4.30, the Sun was getting low and producing even more beautiful images around us to lock into our minds and cameras both. Golden yellow clouds surrounded by beautiful blue-green sky.

We reached Dehradun ISBT around 6.30pm and hopped into the bus, when suddenly people frantically got up and went into another bus which left earlier than ours, however it left us with more seats to adjust with. The long journey scenic journey of Mussoorie had come to an end, we reached Hrishikesh around 8.30. Yet again crossed the Ram jhula in darkness, with only the smells and sounds of the hissing river beneath. On the road back to the Ashram around 9.00 we managed to have some typical north indian food, chhole, tandoori rotis and daal. Sleep wasn’t far away at 10.00pm