Sunday, December 11, 2011

போராளி – திரை விமர்சனம்

போராளி – திரை விமர்சனம்

‘போராளி’ -படத்தின் பெயரே படத்தின் கதை என்ன என்று யோசிக்க வைக்கிறது. அதுவும் சமுத்திரகனி இயக்கத்தில் சசிகுமார் நடிக்கும் படம் என்றவுடன் எளிதாக ரசிகர்களை திரை அரங்கிற்கு இழுத்து விடுகிறது இந்த ‘போராளி’. காரணம் இதற்க்கு முன் இவர்கள் ‘நாடோடிகள்’ மூலம் கொடுத்த வெற்றி தான்.

சசிகுமாரும்(குமரன்), அல்லரி நரேஷும்(நல்லவன்) சாதிக்க வேண்டும் என்ற நோக்கத்துடன் சென்னைக்கு வருகின்றனர். இங்கு அல்லரி நரேஷின் நண்பனாக வரும் கஞ்சா கருப்புவுடன் தங்குகின்றனர். பின்பு வேலை தேடி அலையும் நேரத்தில் இருவருக்கும் ஒரு பெட்ரோல் பங்கில் வேலை கிடைக்கிறது. அங்கு வேலை பார்க்கும் நிவேதா(தமிழ் செல்வி) மீது அல்லரி நரேஷிற்க்கு காதல் ஏற்படுகிறது.

சசிகுமார் குரூப் தங்கியிருக்கும் வீட்டிற்கு எதிர் வீட்டு பகுதியில் சுவாதி(பாரதி)யின் குடும்பம் தங்கியிருக்கிறது. சசிகுமாரும், சுவாதியும் ஆரம்ப சந்திப்புகளில் மோதிக்கொண்டாலும், பின்னர் ஏற்படும் சில நிகழ்வுகளால் காதல் வயப்படுகின்றனர்.

பெட்ரோல் பங்கில் வேலை பார்க்கும் சசி குமார், அல்லரி நரேஷ் மற்றும் தமிழ் செல்வி ஆகியோர், இப்படியே இருந்தால் வாழ்வில் முன்னேற முடியாது என்பதை உணர்ந்து, புதுமையான முறையில் யோசித்து ‘கட்டண சேவை’ என்ற ஒரு புது சேவையை ஆரம்பிக்கின்றனர்.

ஒருவருக்கு அவரது வீட்டு எலெக்ட்ரிக் பில் கட்டுவது அல்லது வீட்டிற்கு தேவையான பொருள்களை வாங்குவது என எந்த வேலை என்றாலும் இந்த கட்டண சேவை பிரிவிற்கு தகவல் தெரிவித்தால் போதும். சசிகுமார் குரூப் அந்த வேலையை செய்து முடித்து விட்டு, அந்த சேவைக்கு உரிய கட்டணத்தை பெற்றுக் கொள்கிறது.

இந்த புதிய சேவை மக்களிடம் பிரபலமாக இவர்களது பிஸினெஸிம் சீக்கிரமாக வளர்ந்து வருகிறது. இத்தருணத்தில் சசிகுமாரை தேடி சிலர் வருவது மட்டுமின்றி, அவரை ஒரு பைத்தியக்காரன் என்று அங்கிருப்போர்களிடம் சொல்லுகின்றனர். இவர்களை கண்டதும் சசிகுமாரும் ஓடி ஒளிகிறார்.

அங்கே துவங்கும் பிளாஷ் பேக்கில் சசிகுமார் இரண்டு பேரை கொலை வெறிகொண்டு துரத்துகிறார். அங்கே வருகிறது இடைவேளை…

சசி குமார் ஏன் அவர்களை பார்த்து ஓடினார்? பிறகு அவர் ஏன் மற்ற இருவரை கொலை வெறியோடு துரத்துகிறார்? உண்மையில் சசி குமார் யார்? சசிகுமாரை பைத்தியக்காரன் என ஏன் அந்த கும்பல் சொல்லியது? இவர்களது பிஸினெஸ் என்ன ஆனது? என்பதை இரண்டாம் பாதியில் விறுவிறுப்பான திரைக்கதையுடன் விடை தருகிறார் சமுத்திரக்கனி.

சசி குமார் ஏற்கனவே தன் நடிப்பு திறமையை வெளிப்படுத்தியிருந்தாலும் இந்த படத்தில் மற்றொரு முறை அதை நிரூபித்திருக்கிறார். முதல் பாதியில் சென்னையில் நடக்கும் காட்சிகளிலும் சரி இரண்டாம் பாதியில் அடர்ந்த முடியோடு காணப்படும் தோற்றத்தோடும் சரி கனகச்சிதமாக அந்த பாத்திரத்தோடு பொருந்தியிருக்கிறார்.

சுவாதி இவரிடம் செல்போனில் தொடர்பு கொண்டு சிலோன் பரோட்டா வாங்கி தரேன் என்க, அதற்கு சசிகுமாரோ சிலோன்னாலே பிடிக்காது. இதுல சிலோன் பரோட்டாவா? என சொல்லும் போது தியேட்டரில் அப்ளாஸ் விழுகிறது.

அல்லாரி நரேஷின் நடிப்பு படத்திற்கு பலம் சேர்க்கிறது. சமுத்திரக்கனி, சசிகுமார் கூட்டணியில் எப்போதும் நட்பு உயர்த்தி வைக்கப்படும். அதே பார்முலாவை இப்படத்தில் அல்லாரி நரேஷ் மூலம் காட்டியிருப்பது படு நேர்த்தி.

சுவாதி தனது பகுதியை நிறைவாக செய்திருக்கிறார். வில்லன்களை கண்டால் ஓடி ஒளியும் சசிகுமாரிடம் எத்தனை நாள்தான் இப்படி ஓடிக் கொண்டிருப்பது? எதிர்த்து திருப்பி அடித்தால் அவர்கள் ஓடமாட்டார்களா? என்பது போல் சசிகுமாருக்கு ஊக்கம் தரும் நாயகியாக வரும் போது நம் நினைவில் மிளிர்கிறார்.

மற்ற நடிகர்களான நிவேதா, வசுந்தரா, பரோட்டா சூரி, படவா கோபி, ஞானசம்பந்தம் படத்திற்கு படு பொருத்தம்.

ஒரு வித்தியாசமான கதைகளத்தை கொண்டு அதை நன்றாகவே கையாண்டிருக்கிறார் இயக்குனர் சமுத்திரகனி.

படத்தின் முதல் பாதியை நகைச்சுவைகளாலும், எதார்த்தமான சம்பவங்களாலும் கதையை கோர்த்து தந்திருக்கும் சமுத்திரக்கனி, இரண்டாவது பாதியில் விறுவிறுப்பு, ஆக்ஷன் கலந்து அசத்தியிருக்கிறார்.

படத்தில் பாடல்கள் குறைவானாலும் பின்னணி இசையில் நம்மை படத்தோடு ஒன்றிவிட செய்கிறார் இசை அமைப்பாளர் சுந்தர் சி. பாபு.

குறிப்பாக படத்தின் இரண்டாம் பகுதியில் அவரது இசை படத்தின் வேகத்திற்கு நம்மையும் ஒன்றவைக்கிறது.

‘போராளி’, படத்திற்கு ஏற்ற தலைப்பு என்பதை விட தலைப்பிற்கு ஏற்ற படம் என்று கூறலாம். போராளி-போராட்டத்தில் வெற்றி

மயக்கம் என்ன - திரை விமர்சனம்

தனுஷ் மற்றும் ரிச்சா கங்கோபாத்யாய் நடித்து வெளியாகியுள்ள படம் "மயக்கம் என்ன" . இதன் கதையை எழுதி, இயக்கியுள்ளார் செல்வராகவன். ஓம் ப்ரொடக்ஷன்ஸ் சார்பாக இந்த படத்தை ஜெமினி பிலிம் சர்க்யூட் நரயுவனம் வெளியிட்டுள்ளது.

தனுஷ் (கார்த்திக் சுவாமிநாதன்) என்ற பாத்திரத்தில் நடித்துள்ளார். இதில் ஒரு போடோக்ராபிராக தோன்றியுள்ளார் (Wild Life Photographer). இவருக்கு பெற்றோர்கள் யாரும் இல்லை. அதனால், இவரும் , இவரது தங்கையும் சேர்ந்து, நான்கு நண்பர்களுடன்(இரண்டு ஆண் நண்பர்கள், இரண்டு பெண் நண்பர்கள்) சேர்ந்து வாழ்ந்து வருகிறார்கள்.

இந்த நான்கு நண்பர்களில் சுந்தர் என்ற பெயரில் இவன் உள்ளான். அவன் தனது அலுவலகத்தில் பணிபுரியும் ஒரு பெண்ணை (கதாநாயகி ரிச்சா) காதலித்து வருகிறான். ரிச்சாவுக்கு தனுஷ் மீது காதல் உள்ளது. நண்பர்களுக்காக அவளை வேண்டாம் ஒதுக்கினாலும், தனுஷுக்கு ரிச்சாவின் மீது உள்ளுக்குள் காதல் உள்ளது.

தனுஷ் அவள் மீது வைத்திருக்கும் காதல் எல்லோருக்கும் தெரிய வருவதன் மூலம், இவர்கள் இருவருக்கும் திருமணம் நடத்தி வைக்கிறார்கள். இப்படியாக இவர்கள் வாழ்கை சென்றுக் கொண்டிருக்க, தனுஷிற்கு ஒரு விபத்து நடக்கிறது. அந்த பிரச்சனை ஏற்படுகிறது. அந்த பிரச்சனை மற்றும் விபத்திலிருந்து மீண்டு வருகிறாரா இல்லையா? மீண்டு வந்து, தனது மனைவியின் உதவியின் மூலம் எப்படி ஒரு மிகப்பெரிய Wild Life Photographer ஆகிறார் என்பதே மீதி கதை.

தனுஷ் நன்றாக நடித்துள்ளார். ரிச்சாவைப் பார்த்து அவர் "போடி முண்டகலப்பை" என்று கூறும்போது கைதட்டல்கள் ஏராளம். மனநலம் சரியில்லாத கட்டத்தில் தான் செய்த தவறுகளை கூறி புலம்பும் போது அசத்துகிறார். ரிச்சா கங்கோபாத்யாய இந்தப்படத்தில் நடிப்பில் அசத்தியுள்ளார். தனுஷை கட்டுப்படுத்த முடியாமல் தவிக்கும் காட்சிகளில் நன்றாக நடித்துள்ளார்.

பிற நண்பர்களாக வருபவர்களின் நடிப்பு ஒ.கே. பாடல் காட்சிகளின் ஒளிப்பதிவு நன்றாக உள்ளது. ஜி.வி.பிரகாஷ் குமாரின் இசை மற்றும் பின்னணி இசை இரண்டுமே பாராட்டிற்குரியது.

ஒரு சிறிய மாற்றம். இப்போது வரும் படங்களில் அவரது சிலுமிஷங்கள் கட்டுக்குள் உள்ளது.
இது ஒரு மனநலம் பாதிப்புக்கு உள்ளானவர் பற்றி சொல்லும் படம். படம் கொஞ்சம் பொறுமையாக செல்கிறது. பார்க்கும் பொறுமை உள்ளவர்களுக்கு நல்ல படம்.

மொத்தத்தில், சமீபத்தில் வெளியாகியுள்ள படங்களில், "மயக்கம் என்ன", நன்றாக உள்ளது.

7 ஆம் அறிவு-திரை விமர்சனம்

ரெட் ஜயண்ட் மூவிஸ் சார்பாக உதயநிதி ஸ்டாலின் தயாரித்து வழங்கும் படம் "7 ஆம் அறிவு". ஏ.ஆர். முருகதாஸ் இதை இயக்கியுள்ளார்.

"ஏழாம் அறிவு" படத்தில் கதாநாயகனாக சூர்யாவும், கதாநாயகியாக உலக நாயகன் கமலஹாசனின் மகளான ஸ்ருதி ஹாசனும் நடிக்கிறார்கள். இன்னொரு நாயகியாக ‘நாடோடிகள்’ படத்தில் நடித்த அபிநயா நடித்துள்ளார்.

"7 ஆம் அறிவு" ஒரு மருத்துவ-வரலாற்று-விஞ்ஞான படம். சூரியவின் வாழ்வில் இது ஒரு மிக முக்கியமான படமாக இருக்கும். புத்த பிட்சு-வான போதிதர்மன் என்ற பாத்திரத்திலும், அரவிந்த் என்ற சர்க்கஸ் கலைஞர் என இரண்டு வேடத்தில் நடித்துள்ளார் சூர்யா. தமிழ் சினிமாவில் முதன் முதலாக அறிமுகமாகும் ஸ்ருதிஹாசன், சுபா ஸ்ரீநிவாசன் என்ற விஞ்ஞானி வேடத்தில் நடித்துள்ளார். "கஜினி" படத்தில் வித்தியாசமான வில்லனை அறிமுகப்படுத்தினார் ஏ.ஆர். முருகதாஸ். அதேபோல், இப்படத்திலும் வியட்நாமிலிருந்து ஜானி ட்ரை நியுயன் (Johnny Tri Nguyen) என்ற வில்லனை இறக்குமதி செய்திருக்கிறார். இவர் கராத்தே, குங்பூ உள்ளிட்ட பலவிதமான தற்காப்புக் கலைகளை கற்றிருக்கிறார். "கிராடில் 2 தி கிரேவ்" (Cradle 2 the Grave) என்ற ஹாலிவுட் படத்தில் பல வியக்கவைக்கும் ஸ்டண்ட் காட்சிகளில் நடித்துள்ளார். "ஸ்பைடர் மேன் – 2 " படத்தில் ஸ்பைடர்மேனுக்கு டூப் போட்டு நடித்தவர் என பல சிறப்புகளை உடையவர் ஜானி. இப்படத்தில் இடம் பெற்றுள்ள சண்டைக் காட்சிகள் ஹாலிவுட் தரத்திற்கு இருக்கிறது.

"7 ஆம் அறிவு" படத்தின் கிளைமேக்ஸ் சண்டை காட்சிகளில், வில்லன் நடிகர் ஜானி டிரை நுயென்னுடன் மோதுகிறார் சூர்யா. இந்த சண்டைக் காட்சியை குங்பூ தற்காப்பு கலையை மையமாக்கி எடுத்திருக்கிறார் ஏ.ஆர்.முருகதாஸ். இதற்காக சூர்யா சிறப்பு பயிற்சிகளை மேற்கொண்டார். இப்படத்தின் சண்டைப் பயிற்சி பொறுப்பினை மேற்கொண்டார் பீட்டர் ஹைன்.

"7 ஆம் அறிவு" படத்தின் கதை 5-ஆம் நூற்றாண்டில், பல்லவ சாம்ராஜ்யத்தில் வாழ்ந்த போதிதர்மன் என்ற புத்த பிட்ஷுவின் வாழ்க்கையை காண்பிக்கும் விதத்தில் துவங்குகிறது. இவர் தற்காப்பு கலைகளிலும், மருத்துவத்திலும் நிபுணத்துவம் கொண்டவர். இவர் தனது பெற்றோர்கள் ஆணையை ஏற்று சீனா செல்கிறார். அங்கு சிறிது காலம் வசிக்கிறார். அப்பொழுது, அங்குள்ளவர்களை, ஒரு விதமான நோய் வந்து தாக்குகிறது. அப்போது, அவர் தனது மருத்துவத்தின் மூலம் அங்குள்ளவர்களை காப்பாற்றுகிறார். இதனால், அங்கிருந்த மக்களுக்கு அவர் மீது உள்ள மரியாதை கூடுகிறது. அவரை வணங்க துவங்குகின்றனர்.


பின்னர் ஒரு சமயம், அருகிலுள்ள பகுதியிலிருந்து எதிரிகள் வந்து, இவர் வாழ்ந்த பகுதியிலிருந்த மக்களை தாக்குகின்றனர். அவர் தனது கலைகளை பயன்படுத்தி இவர்களை காக்கின்றார். அந்த பகுதி மக்கள் அவரிடம் அந்த தற்காப்பு கலைகளை கற்று தரும்படி கேட்கின்றனர். எனவே, அக்கலை-களை அவர்களுக்கு கற்றுக் கொடுகின்றார். பின்பு, அங்குள்ளவர்களுக்கு கடவுள் போலவே மாறிவிடுகின்றார்.

அங்கிருந்து திரும்ப வரும் முயற்சிக்கும் போது, அவரை திரும்ப அனுப்ப அங்குள்ளவர்கள் விரும்பவில்லை. அவர் அங்கேயே இறந்து, அவரை அங்கேயே, புதைத்தால் அவரிடம் இருக்கும் சக்தி அந்த மண்ணிலேயே தங்கிவிடும் என்று சுயநலம் கொண்டு அவருக்கு விஷம் கொடுக்கின்றனர். அவர்களின் எண்ணங்களை உணர்ந்துக் கொண்ட அவர், அவ்விஷத்தை அருந்தி இறந்து விடுகின்றார்.

இதே நேரத்தில், சர்கஸில் பணிபுரியும் சூர்யாவையும் (அரவிந்த்) காண்பிக்கின்றனர். சுபா எனப்படும் விஞ்ஞானியாக வரும் ஸ்ருதி, 1600 ஆண்டுகளுக்கு முன்பு போதிதர்மன் (D.N.A) உடலின் மூலப்பொருள்கள், இப்போது உள்ளவர்களிடமும் இருக்கும் என்பதை கண்டுப்பிடிகின்றார். அது இப்போது அரவிந்தின் உடலில் இருக்கிறது என்று கண்டறிகிறார். இதனால் அவரை சந்திக்கின்றார். இதற்கிடையில், இவர்களுக்குள் காதல் மலருகிறது. சுபா வெறும் காதலுக்காக மட்டும் தன்னுடன் பழகவில்லை என்பதை கண்டுபிடித்து விடுகின்றார் அரவிந்த். இதனால், அனைத்து உண்மைகளையும் கூறுகிறார் சுபா. அதை கேட்ட அரவிந்த், தன்னால் இயன்ற அளவுக்கு சுபாவின் ஆராயய்ச்சிக்கு ஒத்துழைக்கிறார்.

இதற்கிடையில் ஆபரேஷன் ரெட் எனப்படும் ஒரு உளவுப் பணியை மேற்கொள்ள வருகிறார் டோங்க்லீ (ஜானி) என்ற வில்லன். ஆபரேஷன் ரெட் யாதெனில் 1600 வருடங்கள் முன்பு சீனாவை தாக்கிய அதே கிருமியை, இப்போது இந்தியாவில் பரவச்செய்ய வேண்டும் என்பது தான். அவ்வாறு பரவ செய்து, அதற்குண்டான மருந்தினை சீனாவிலிருந்து மட்டும், இந்தியாவை வாங்கவைக்க வேண்டும் என்பதே முக்கிய குறிக்கோள். இதனால் இந்தியாவை, மருத்துவ ரீதியாக சீனாவை சார்ந்திருக்க செய்ய வேண்டும், என்பதே இந்த ஆபரேஷன் ரெட்டின் மிக பிரதான திட்டமாகும்.

(*) இந்த ஆரரேஷன் ரெட்டில், யார்-யார், யாரிடம் வெற்றிக் கொள்கின்றனர்?

(*) போதிதர்மனின் மூலபொருட்களை மீண்டும் அரவிந்தின் உடலில் செலுத்தி, அதனால் இந்திய நாட்டிற்கு நன்மைகள் பெற்றுக் கொள்ள முடிகிறதா? இல்லையா?

(*) சீனாவிலிருந்து வரும் வில்லன் வெற்றி காண்கிறாரா? அல்லது சுபா மற்றும் அரவிந்த் அவர்களின் ஆராய்ச்சிகளில் ஜெய்க்கிரார்களா என்பதை மிக சுவாரஸ்யமாக க்ளைமாக்சில் காண்பித்துள்ளனர்.

இக்கேள்விகளின் விடையைத் தெரிந்துக் கொள்ள "7 ஆம் அறிவு" படத்தை காணுங்கள்.

"எந்திரன்" படத்திற்கு கிராபிக்ஸ் காட்சிகளை வடிவமைத்த அதே நிறுவனத்தில் தான், இப்படத்தின் கிராபிக்ஸ் காட்சிகளையும் வடிவமைத்திருக்கிறார் இயக்குனர் ஏ.ஆர். முருகதாஸ். இதன் கிராபிக்ஸ் காட்சிகள் "எந்திரன்" படத்திற்கு நிகராக உள்ளது.


இதில் இடம் பெற்றுள்ள ஒரு பாடலுக்கு மட்டும் 1000 நடனக் கலைஞர்கள் ஆடியிருக்கிறார்கள். இதுபோல் பல பிரம்மாண்டங்களை கொண்டுள்ளது இந்த படம்.


இதன் ஒளிப்பதிவை மிகவும் திறன்பட மேற்கொண்டுள்ளார் ரவி கே. சந்திரன். ஆண்டனி படத்தொகுப்பு வேலையை தெளிவாக செய்துள்ளார். "7 ஆம் அறிவு" படத்தின் இசையை அமைத்துள்ளார் ஹாரிஸ் ஜெயராஜ். இதற்காக, பழங்கால இசைக் கருவிகளை பற்றி நாடுகள் சென்று ஆராய்ச்சி செய்து, பின்பு இசையமைத்தினர்.

இத்தனை காலம் நாம் தெரிந்துக்கொள்ள தவறிய போதிதர்மன் வாழ்கையை பற்றி அறிந்துக்கொள்ளும் விதாமாக, இப்படத்தை வழங்கிய ஏ.ஆர். முருகதாஸ் அவர்களுக்கு நன்றி கூறியே ஆக வேண்டும். இப்படத்தின் கலை, இசை, சண்டைக் காட்சிகள், பாடல்கள் உள்ளிட்ட அனைத்து அம்சங்களும் சூப்பர். மொத்தத்தில், இது அனைத்து தமிழ் மக்களும், அனைத்து இந்தியனும் பார்த்து பரவசம் அடைய வேண்டிய ஒரு அருமையான படம். இந்திய சினிமாவை உலக அரங்கில் கொண்டு செல்லும் படங்களில், இந்த "7 ஆம் அறிவு" படத்திற்கும் முக்கிய பங்கு நிச்சயம் உண்டு.

Monday, October 3, 2011

How to Force download multiple files in a zip archive using PHP

In this post, I’ll show you how can you download the multiples files in a zip archive using PHP. I’ve made a function in PHP where you’ve to pass the parameters the array of files to be zipped, the second parameter is file name as which zip archive file has to be downloaded and finally the path of files where files to be zipped are located.(assuming that they are all in same folder)

PHP function to download mutiple files in a zip archive

//function to zip and force download the files using PHP
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
//create the object
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}

//add each files of $file_name array to archive
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
}
$zip->close();

//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}


In the above PHP function, first of all the object of ZipArchive class. Remember that this library is bundled in PHP after the version of PHP 5.2 only.If you’re using the PHP version older than that one then you’ve to get it from PECL extension.

After that, we’ve tried to create the zip arhive with the open() function using the ZIPARCHIVE::CREATE flag.After successfully creating the archive, each files whose names are passed as array are added to zip file using addFile() function of ZipArchive() class.Then, this zip archive is closed using close() function of same class.

And, finally different headers are passed through PHP to force download the newly created zip file.
Example of Using Above PHP function

$file_names=array('test.php','test1.txt');
$archive_file_name='zipped.zip';
$file_path=dirname(__FILE__).'/';
zipFilesAndDownload($file_names,$archive_file_name,$file_path);

The above PHP function call is straighforward and after calling that function you’ll get the zip archive containing mutiple files passed as array in the first parameter of the function.

How to Change textbox value from dropdown list using Ajax and PHP

Yesterday Tarquin macey asked me how can we change the value of the textbox based using Ajax and PHP based on the changing value of the dropdown list.Today, I’ve come up with a solution from him.In this post, you’ll see how to get the currency code of a country from PHP using Ajax and this currency code will replace the value of textbox each time the dropdown list changes.

View Live Demo
Writing Code for changing textbox value from dropdown list using Ajax and PHP

After looking at the above demo, let’s start writing code for the changing the currency code value in the textbox form Ajax using PHP when you changes the country from the dropdown list.

HTML Code




As you can in the above code, there are two main components one dropdown list whose name is country and contains the list country in it.The JavaScript function getCurrencyCode() is called when user change value in the list. Note down the name and id of textbox which will have the currency code fetched from Ajax.

JavaScript Code for changing textbox value without refreshing the page

function getCurrencyCode(strURL)
{
var req = getXMLHTTP();
if (req)
{
//function to be called when state is changed
req.onreadystatechange = function()
{
//when state is completed i.e 4
if (req.readyState == 4)
{
// only if http status is "OK"
if (req.status == 200)
{
document.getElementById('cur_code').value=req.responseText;
}
else
{
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}

In the first line of the above code, the XMLHTTPRequest object is created using getXMLHTTP() function. To look at the the structure of this function, take a look at this old post change the value of dropdown list using Ajax and PHP . After checking the appropriate value of readystate(4 means completed) and status(200 means ok) property of XMLHTTPRequest object, the value of textbox is replaced with the returned value from PHP using Ajax . The response ,which is can be accessed via req.responseText property, is written to textbox via the value property of textbox.

PHP code for changing the value of textbox using Ajax and PHP



As you can see the above PHP code, it is fairly simple which just print the currency code value according to the name of country. The value which is in the echo statement is going to returned from PHP via Ajax.

how to Solve Floating point number precision lost problem in PHP

The problem of precision lost in floating point number in PHP haunted me for about 10 minutes yesterday but I quickly figured out the problem and solved it as I was aware of this problem. But, I would like to post here it here so that many others PHP programmers, who are not aware with this kind of problem ,get solution easily and don’t get stuck with it.

Calculation problem floating Point number in PHP

First of all, let me show you a small piece of example of the PHP code which I was working on.

$no_of_time=(0.60-0.55)*100;
var_dump($no_of_time); //displays float(5)
for($i=1;$i<=$no_of_time;$i++)
{
echo $i;
}

In the above code, the line var_dump($no_of_time); displays float(5). Ok, this is a expected result. But what about the loop, which runs just for 4 time. The above loop runs just for four time although var_dump () outputs that it is 5. Yes, it is 5 but with lost precision and that why never ever trust on the regular arithematic calculation with the floating point numbers in PHP. It always gives the wrong result because of the problem of lost precision. You can also see this warning in the PHP’s website.
Solving the problem of floating point precision in PHP

To solve this problem in floating point number, you need the function which calculates and support the calculation of floating point number of any precision. And, I recommend you to use BC Math functions, the binary calculator, of PHP for calculations of floating point number to prevent yourself from the problem of precision lost. But note down that, these functions always returns calculated output as string.Now, let’s try to solve the problem of above code rewrite it using bcsub and bcmul functions of PHP.

$no_of_time=bcmul(bcsub(0.60,0.55,2),100);
var_dump($no_of_time); //display string(1) "5"
for($i=1;$i<=$no_of_time;$i++)
{
echo $i;
}

Now the above, loop runs 5 times without any problem.

How did I reduce CPU overhead problem caused by MySql

From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP file was creating the overhead to the CPU of the server.
Problem of CPU Overhead with MySql

Let me explain the problem clearly first,

We’re working on a website which was similar to http://www.swoopo.co.uk/ and as you can see clearly in that website the most recent data should be fetched form MySql database in each second. in the PHP page, which was being called from Ajax every second, had around 5 SQL queries to retrieve data from server.

First of all, I optimized that page reducing the 5 queries into single query by using left outer joins among 3 tables. And then, I did benchmark test by using Apache benchmark tool(ab) 50 request with concurrency of 50 with the following command.

ab -n 50 -c 50 http://xyz.com/ajax_page.php

And then in another SSH shell prompt, I run the top command to view the CPU usages parallelly.

I was still horrified that the CPU usages by mysql after 50 concurrent user was going out of control(100%) despite of optimized query. But many joins have been used in that single query and lots of data were there in those tables so the database overhead was high even though it was a single query.
How did I reduced the CPU overload drastically caused by MySql?

Now, the first challenge was to reduce the database access. It was clear that it was caused by concurrent database overhead in the PHP page which was being called in every second. Here is the simple steps what I did to reduce the database overhead.

1. I created another PHP file in which I’ve transferred the mysql query causing CPU overhead and called it from Cronjob.
2. Created a temporary table for storing the output given by PHP page called from CronJob.
3. Then, I scheduled the CronJob in every second, don’t tell me that CronJob can’t be run less than a minute, take a look at this post before saying this.And from each call, the output data was stored in the temporary table.
4. And, finally from the Ajax the a new PHP page was called which was only accessing the data from temporary table with single row.

I did the same benchmarking again to the newly made page(which is accessing data only from temporary table) and saw that CPU usages after the this process reduced drastically.