Monday, November 01, 2010

php-fpm with nginx on macosx

PHP 5.3.3 is bundled with php-fpm, however the macports version doesn't have a fpm variant yet. There are very few blogs that talk about setting up php-fpm with nginx on macosx. So I have documented here the steps I have followed to get them working.

1)port uninstall installed and php5
2)port selfupdate
3)edit /opt/local/var/macports/sources/rsync.macports.org/release/ports/lang/php5/Portfile
and add "--enable-fpm" option to the configure.args. More details about this can be found at http://serverfault.com/questions/170394/nginx-and-php-fpm-on-os-x
4)Install the fastcgi variant of php "port install php +fastcgi"
5)Check if you have /opt/local/sbin/php-fpm binary
6)Configure /opt/local/etc/php-fpm.conf
7)Create a plist file called org.macports.phpfpm.plist. I created a simple plist file with /opt/local/sbin/php-fpm as the only string tag. I suggest that you read about plist files and create a proper plist file.
8)copy the plist file to /Library/LaunchDaemons/org.macports.phpfpm.plist
9)add the plist to file to startup "sudo launchctl load -w /Library/LaunchDaemons/org.macports.phpfpm.plist"
10)reboot the machine, verify if php-fpm is running. "ps aux | grep fpm"

Tuesday, September 07, 2010

Bangalore-Yercaud-Bangalore Cycle Ride



For those who don't know this yet, five of us rode from Bangalore to Yercaud on Saturday. Here is the ride report for the benefit of others interested in riding to Yercaud.

My alarm went of at 2:00am on saturday morning. I finished my morning chores and started from my home at 3:15am. After just a few meters of riding I got a call from Shashi confirming that all other rides have started and were on their way to Silkboard. I started pedaling slowly and met Ramey (another rider in crime) less than a kilometer from my home. After a brief conversation, he cruised ahead to silkboard. I was riding slowly. The road was mostly empty except for the night patrol. I reached Silkboard and waited for Shashi and other riders from Kanakapura road to join us. Shashi, Harisha & Prakash arrived at Silkboard a few minutes later. Myself, Shashi and Ramey were on hybrids, Harisha and Prakash were on mountain bikes.

We all started from Silkboard at 4:05am. The road was lit up with streetlights till Electronics City after which it was dark. We rode mostly on the service roads till we reached Hosur, where we stopped for tea at around 5:15am. By the time the sun came up, we were half way between Hosur and Krishnagiri. The route from Hosur to Krishnagiri was full of downward slopes. We stopped for breakfast at 7:30am at Krishnagiri near the Krishnagiri-Chennai diversion. We rode at an average speed of 32km/hr from Hosur to Krisnagiri. Shashi had convinced his brother Sridhar and his friend Sandeep to come to Yercaud in a car. Special thanks to them for carrying our bags. Sridhar and Sandeep arrived at our breakfast place just before we finished our breakfast.

We left the restaurant at 8:30am and headed toward Dharmapuri. We stopped for tea somewhere before Dharmapuri. I don't remember the time we crossed Dharmapuri, but we reached a place called Deevattipatti around 2:30pm. We stopped for snaps at multiple places before Deevattipatti. We decided to take a shortcut to Yercaud avoiding Salem. Harisha had a puncture before Deevattipatti. Luckily there was a puncture shop close by and we got it fixed quick. We took a diversion from Deevattipatti towards a place called Danishpet. The road from Deevattipatti to Danishpet had only a single lane. It was surrounded by a few streams and lakes. We stopped at Danishpet before a railway cross for tea. Danishpet to Yercaud base was around 25km. Taking that route turned out to be the biggest blunder we made. The route was full of mud and stones. There were no roads at all in some parts. We had to lift our cycles and walk to cross one of the small streams. It is worse than the worst road you would find along the Anchetty-Hogenakkal route. Luckily none of us were on road bikes. I wonder why Google maps lists these roads. Every local we asked said the main road was 2-3km away at every point. But we never seemed to hit the main road. After cycling around 25km we reached the main road. We took almost 3 hours to cover those 25km in jungle. My front tire was flat once we crossed the forest region. I didn't have the patience to fix the puncture. So we just changed to the spare tube and headed to Yercaud base.

We reached Yercaud base at 6:30pm. We took a few snaps at the 1st hairpin bent. It was already dark and we had 21km with 1594 meters of ascent to climb. Unlike Nandi, the hairpin bends were smoother, but the straight roads were steeper. I climbed along with Harisha and we took breaks almost every couple of kilometers. There were lot of monkeys along the way. We ran out of all the water we had and there were no places along the way to get water from. It drizzled for a brief period, and we stopped under the shelter of something that looked like resting place for travelers. Couple of other people stopped at the same place and shared their water with us. We were only half way to Yercaud and we were extremely hungry. Luckily Harisha had some dry fruit. Shashi was hitching along with a moterbike and came to the top. Shashi mentioned that one of the police guys said that there was a bison roaming around, but we never encountered the bison. Three of us started climbing together. After another couple of kilometers we ran out of water again. At the same spot we found a hut in one of the coffee plantations and filled our water bottles there. After having water and dry fruit, we started climbing again. Ramey and Prakash boarded a lorry that was climbing up. At 6km point the lorry caught up with us. The lorry guys offered to give us a lift, but we declined and continued to climb. At around 10:15pm we reached the top. We rode the Lake Forest resort from the top. We had covered 236km in total. Sridhar and Sandeep had arranged for a nice dinner. We freshened up, had dinner, and dozed off.

The next day we went around Yercaud for sightseeing on our bicycles. Shashi went to Salem with his brother to meet his relatives. The rest of us went to couple of temples, and went boating. I roamed around one of the coffee plantations. I dozed of at about 8:00pm. I guess everyone else had dinner after that.

We started back from Yercaud at 4:15am on Monday. We rode slowly till the base. Stopped multiple times for snaps. The sky was clear and the stars were clearly visible. The moon was yet to rise, I guess. The horizon was also clearly visible. It is one of the best places for star gazing. I wished I had woken up couple of hours earlier to gaze at the sky. BAS (Bangalore Astronomical Society) members would love the place. The view of salem from the top was also awesome. We met a few people jogging at the base, took a few snaps at the last hairpin bent.



Ride from Salem was uneventful till the Dharmapuri ghats. We stopped for tender coconuts at multiple places. Sridhar and Sundeep were on their car and caught up with us close to the toll booth before Dharmapuri. Harisha had a puncture at the toll booth. We removed his tire and I took it to the nearby puncture shop to fix. One of the moterbikers offered Harisha a lift and he came to the puncture shop carrying his bike. We got the puncture fixed and went to A2B before Dharmapuri. Shashi and Prakash were done with breakfast by the time we reached and they started riding ahead of us while we had breakfast. After breakfast we started climbing the Dharmapuri-Krishnagiri ghats. It was a steep upward slope and we took multiple breaks. We reached Krishnagiri at 1:30pm. Shashi and Prakash had also arrived a few minutes before. All four of us had lunch and started riding towards Hosur. Krishnagiri-Hosur route was full of steep ascents. We had cruised the same route at 32km/hr during our onward journey; on the way back we stopped multiple times. I guess we were riding at 15-18km/hr. Shashi had a puncture and fixed it with Prakash while Harisha and I stopped at a dhaba and had some food. At around 5:30pm they caught up with us at the dhaba. Hosur was around 20km away from us from where we were. We started riding and reached hosur around 7:00pm. Hosur has some of the worst possible roads. The local traffic mixes with the highway traffic and there were lot of people riding on the wrong side. It was very difficult to cross Hosur. Me and Harish reached Silkboard at 8:45pm and parted ways to our homes. At around 9:15pm I reached my home. The 470km ride was over! Got a call from Shashi at 9:30pm informing that he has reached home.

Monday, August 02, 2010

My First Ride To Nandi Hills - Biking Carnival



It has been a week since I bought a trek 7100. I have been waiting for an opportunity to go for a long distance ride. Bikers from Bangalore Bikers Club (BBC) were organizing the month end long ride to Nandi hills. So I decided to bike along with other bikers to Nandi on 1st of August. More than 100 people signed up for the ride.

I woke up at 4:00am on 1st August, took a shower, drank two liters of water, finished my other morning rituals and went to Cubbon park at 5:30am along with Ram. We were the first two bikers to reach Cubbon park. During the next few minutes, bikers started to pour into Cubbon park. Ram borrowed a hand pump from one of the riders and inflated both of his tires. There were roughly 30 bikers at Cubbon park by 6:15am. Kiran Jonnalagadda and Nitesh were also there. Yogesh from BBC made few announcements about support vehicles, safety measures and emergency contact numbers.

At 6:15am we left Cubbon park. I was riding with Ram and Nitesh until Yelahanka. After reaching Yelahnaka, I broke away from the group and started riding ahead. I met Yohesh on the way, had a small chat with him and broke away from him. We had Army trucks, and jeeps riding along with us. There were few guys distributing juice to riders on the way. We were riding in the airport road on the shoulders. Around 7:30am or so I reached Bangalore International Airport, which is 40km away from the city. I took a diversion there that led to Devanahalli. The road to Devanahalli was less crowded. I overtook two fellow bikers somewhere between BIAL and Devanahalli and one of the bikers shouted Deepan. It was Venugopal riding his Btwin sports bike. I had a small chat with him and cruised to the front. I overtook a long truck along the way and the truck again overtook me. I smiled at one of the guys in the truck and he smiled back. I guess I was at Devanahalli at around 8:00am.

There were few riders at the Nandi road diversion in Devanahalli chit chatting. The road to Nandi from Devanahalli was little narrow, but was almost empty. The ride to idly point from Devanahalli was uneventful. There was a billboard on the way that said: "The Falcon is coming". I reached idly-point at around 8:30am. I stopped for breakfast. The idly shop ran out of idlies because of the biking crowd. I had rice bath and started again.






I reached Nandi statue at the base of Nandi hill at 9:05am. Riding until this point was quite easy. I guess I rode at an average speed of 25km to 30km per hour. I remember at one point my speedometer read 44km per hour. Now I changed my gears to 1-3 and started climbing up the hill. Within the first few hundred meters I realized that it is excessively difficult for me to climb at 1-3 gear. I changed to 1-2 combination and started pedaling. Opendro was climbing along with me. He said that this was his second Nandi ride. My bike was making some noise at 1-2 gear. He suggested that we fix my gears. So we stopped and Opendro fixed my gears. We started riding again, and the noise from my gears was gone. We came across another rider fixing his bike. Opendro stopped to help him and I continued. The ride up the hill was the most difficult part. I was riding almost at walking speed. There were few riders riding downhill at full speed. Almost every rider riding downhill was smiling, encouraging uphill rider. Almost after half an hour of pedaling up I saw the Nandi signboard that said 5km. There few people and parked cars on the way. Some of them were posing for pictures. Somewhere along the way I changed to the lowest gear possible. I was pedaling uphill through the clouds. I badly wanted to stop, but resisted in order to not lose the momentum. A government jeep overtook me somewhere close to the top. It read RTO on the back. The acronym RTO stands for Road Transport Officer. The RTO of Devanahalli was driving to Nandi top to greet all the riders. The RTO was smiling at me when the jeep overtook me. I saw the 2km signboard sometime after that. There was a rider coming down and he said: "You are almost there". I felt encouraged. The last two kilometers ride on the top seemed to be going forever. I was probably riding slower than walking speed. I remember the speedometer reading 5km or 6km per hour. I was pedaling at 1-1 combination in standing position at one of the U-turns at top. There were moments when I felt that the cycle was standing still. After that I saw the arch on top of Nandi. I was very happy.









When I entered the arch there were few people distributing juice. They said there was breakfast on top. I enquired how long it is. The guys said two kilometers. It was disappointing to know that I have to climb two more kilometers for breakfast. Fortunately the road further was not that steep. I rode to the top and RTO was greeting everyone. He had also arranged free upma, lemon rice, coffee and tea for all the riders. I was cursing myself for having had breakfast at the idly point. I had breakfast once again.

After breakfast, I tried calling Ram to figure out where he was. He was not reachable. So I decided to ride back searching for him. I crossed the arch and rode few hundred meters. In one of the hairpin bends I saw Ram coming up. He said his thighs were paining. Together we walked up the last few hundred meters and reached the arch. We walked uphill after a stopping briefly for pictures. We reached breakfast point. I had a coffee again while Ram had breakfast. After resting for an hour or so, we started riding back. The downhill ride was awesome. Unfortunately one of the riders met with a small accident. One of the fellow riders was hit by a rogue motorbike rider. We stopped there and called for the medics where riding along with us. Within moments the army jeep was there at the accident spot with the medic and first aid kit. I met Barani at this point. The injured biker left in the army jeep. We started riding back. We reached Nandi base within few minutes. My speedometer was reading 40km on the downhill at multiple spots. Brigadier Vijay had arranged for lunch at the base. We stopped for lunch at the base and started riding back. Riding back was very difficult since I was very tired. I remember reaching Devanahalli at 2:00pm. I was riding at an average speed of around 13km until BIAL. After that my average speed declined further to 10km per hour. Along the way I had jackfruit and tender coconut. I reached Hebbal flyover at around 4:15pm. I reached home at 5:15pm. I cycled 130km in a span of 11 hours. I took a shower again and had dinner. I went to bed at 8:30pm and slept for next 10 hours like a baby. It was a wonderful experience.

I will try to ride to Mysore soon. Stay tuned.





Wednesday, July 07, 2010

Testing your webapp using Selenium and PHPUnit

For a long time we have been testing our websites manually. Finally, we have decided to put in some effort to automate part of this testing. After a little bit of research, we found that Selenium could test any website in any set of browser-operating system combinations. There are some other equivalent tools, however selenium seems to be the most robust.

Selenium has many sub-projects. Selenium IDE is the best place for novices to start. Selenium IDE is a Firefox plugin that lets you record events in Firefox and replay them. Events can be like entering text in an input box. You can record a bunch of events like entering username, entering password, clicking on submit, etc. and replay them. Selenium has client libraries in almost all prevailing languages. You could record set of events in Selenium IDE and export the scripts to any of the supported languages. Java, Python, PHP, Ruby are some of the supported languages.

Replaying a script in Selenium IDE will execute the script inside Firefox. If you wish the execute the script in other browsers, then you will have to use a tool called Selenium RC. The acronym RC stands for remote client. Selenium RC is a jar file which can invoke any browser of your choice and execute the commands that you pass to it.

I have several instances of Selenium RC running, one in Windows, one in Mac and one in Linux. When I execute the PHP test scripts, they connect to Selenium RC running in various machines over the network and execute the scripts on a specific browser. This way you could test your website on all major browser and operating systems.