Thursday, October 18, 2007

Sethu Canal Project

Hi Readers,

I would like to express my view on the sethu Canal project (so called Ram Sethu), I neither offend or defend the existence of Ram here. But the political parties mainly caste parties are taking it a issue and everyone including the ruling government is trying to make votes in the election of of it.

Does it not affects the progress of our nation , Are we going to hurdle each projects this way.

We have to think forward, lets for an argument lets take Rama has built that bridge. Wasn't he doing it against the nature that time and what the problem now coming up.

Its all in the minds of politicians to grab votes from the people.

Crores of money will go wasted which have been invested in that so far, who bears the burden , not the politician but the tax payers.

Development projects with a true concerned should be appreciated and carried out without hurdles.

That is the only way to get in the vision 2020.

Friday, August 24, 2007

PHP PDO

PDO :
Sounds like a catchy word, but true its is a very good module that has been available with PHP 5.

In quick terms I would say this is like a generic odbc database abstraction method, IE you could write applications that can work seamlessly with different databases with it.

Here is the explanation from PHP site

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.


How to get it

Its available as PECL and also as a PHP module.

The PHP module is best and performance and speed. For configuring goto PHP site

How do I use it

$db = new PDO('mysql:host=localhost;dbname=$database', $dbuser, $dbpass)
or

class myclass extends pdo{

function __construct(){

parent::construct('mysql:host=localhost;dbname=$database', $dbuser, $dbpass);

}

/***

my code */


}

and now

$db=new myclass();


There are three important things in the PDO we need to understand

PDO object
PDO Statement object
PDO Error handler


PDO object is the object we insantiate

ie $db=new pdo('mysql:host=localhost;dbname=$database', $dbuser, $dbpass);

where $db is the pdo object.

Lets see an example of connecting and updating a record in a table test

$db=new pdo('mysql:host=localhost;dbname=$database', $dbuser, $dbpass);

$db_stmt=$db->prepare("update test set name=:name,address=:address where id=:id");

now $db_stmt is the PDO statement handle.

We had made the sql prepare here this is very effective when you want to update an array of users like

$users=array(
0=>array("name"=>"name1","address"=>"test1","id"=>1),
1=>array("name"=>"name2","address"=>"test2","id"=>2),
2=>array("name"=>"name3","address"=>"test3","id"=>3));

//note you have to

foreach($users as $key=>$user){
foreach($user as $col=>$val){
//bind the value for :name , :address ,:id here

$db_stmt->bindValue(":".$col,$val);
//to my knowledge the bindValue will work for binding all values.
//I see this bindParam is not working for the values in where class
//refer php manual for more options
}
//execute it
$db_stmt->execute();
}

There you go you should have updated 3 records.

you can always execute in the old way of

$db->exec("DELETE FROM test WHERE id=1");

which will return the no of affected rows for this.

Please put comments if you have any doubts.

Friday, July 27, 2007

A Tribute to South INDIA

Friends
I would like to tribute this video in honor of south India , where I do hail from, This video describes about my native town srirangam and also about the Greatest king Raja Raja Cholan.
Its a 52 mins video but worth seeing.

Google News on Tamil

Monday, June 18, 2007

US Visa Guidelines


Its required to be there at least an hour before the interview time of yours.

Keep your passport and visa interview letter Ready to show to the security at the gate.

Make sure you do not have any mobile or electronic devices or cosmetics or sharp elements with you.

All your covers / letters should be uncovered and never keep some closed cover material.

You need to undergo a clear security check and also they will check all your documents so dont keep any thing in closed cover , take it in a file so that you / they can handle it easily

Next on passing on to a Big heavy door You will be either asked to sit or directly asked to stand in a queue , There hand over your passport / visa interview and the visa application form,Visa payment slip altogether to the person.

The person may ask you to write your name in the application form in your native language and every thing will be given in a file by them and you need to proceed to the next part.

You will be asked to be in a queue and called upon your interview time and in there you will be asked for a biometric finger print recognition of your left index finger and right index finger , here you have to give you passport alone.Once this is over you will be asked either to wait or will be taken to another queue to the visa counselor.

Here on going to the counselor hand over the file given outside in a flat way via that glass door.

Wait till you are called by them and greet the person like Hello , Good morning or approriate to the time you meet them..

Keep your files in handy so that give them the documents what they need do not give the entire folder.

Be clear on your
Purpose of travel.
Date of travel.
Stay.
Sponsor.
Previous travel to US and other countries.(with date and period of stay and purpose)
Your salary(both monthly and annualy)
Your company details
Your Client details



Question generally which were asked was

1) How are you

2) Whom do you work for.

3) What your company do

4) Who is your client

5) What kind of business they do


5) Whats is your monthly or annual salary

6) What is the purpose of visit




Then the counselor will say your visa is approved or not approved.


if approved they will take the passport else they will return it to you.

Wednesday, June 13, 2007

PHP SOAP

Source Article : Developer.apple.com

SOAP, the Simple Object Access Protocol, is the powerhouse of web services. It’s a highly adaptable, object-oriented protocol that exists in over 80 implementations on every popular platform, including AppleScript, JavaScript, and Cocoa. It provides a flexible communication layer between applications, regardless of platform and location. As long as they both speak SOAP, a PHP-based web application can ask a C++ database application on another continent to look up the price of a book and have the answer right away. Another Internet Developer article shows how to use SOAP with AppleScript and Perl.
SOAP was created collaboratively as an open protocol. Early in its development, XML-RPC was spun off, and now enjoys its own popularity as a simpler alternative to SOAP. Both encode messages as XML, and both use HTTP to transport those messages. SOAP, however, can use other transport protocols, offers a number of high-end features, and is developing rapidly. (For more about SOAP and web services, try XML.com’s helpful
demystification.)
A SOAP transaction begins with an application making a call to a remote procedure. The SOAP client script then encodes the procedure request as an XML payload and sends it over the transport protocol to a server script. The server parses the request and passes it to a local method, which returns a response. The response is encoded as XML by the server and returned as a response to the client, which parses the response and passes the result to the original function.
There are a number of different implementations of SOAP under PHP. It’s a shifting landscape: new ones appear, and old ones aren’t maintained or simply vanish. As of this writing, the most viable PHP implementation of SOAP seems to be Dietrich Ayala’s SOAPx4, also known as NuSOAP. This implementation is the most commonly used and appears to be the most fully developed and actively maintained, and it shows every sign of continuing to be a robust and popular solution. It’s not complete—a number of features, including full documentation, are still in the works—but it’s still a highly viable and easy-to-use SOAP solution.
Installation
First, you need to get PHP up and running on your Mac. This is easy to do: check out our
tutorial to get yourself set up. If you want to send SOAP messages over HTTPS, you’ll need to include the cURL module in your PHP build.
The next step is to install NuSOAP. Download the package from the
developer’s site. Unzip it to get a folder of documentation, as well as the file nusoap.php, which contains the actual PHP classes that we’ll need. To use them, place nusoap.php in your PHP path and include it in the scripts you write.
The base class is nusoap_base. By using it and its subclasses, anything is possible. As an example, I’ll build a simple SOAP server script and client script, and then dissect the XML transaction they send.
A SOAP Server
Here is a simple server, written in PHP, that takes an ISBN (International Standard Book Number) as input, performs a lookup in an imaginary database, and returns the price of the corresponding book. In it, I use the soap_server class, and four methods of that class: the soap_server constructor, register, fault, and service
// function to get price from database
function lookup($ISBN) {
$query = "select price from books where isbn = ". $ISBN;
if (mysql_connect("localhost", "username", "passwd"))
else { $error = "Database connection error";
return $error; }
if (mysql_select_db("books"))
else { $error = "Database not found";
return $error; }
if ($result = mysql_query($query))
else { $error = "mysql_error()";
return $error; }
$price = mysql_result($result, 0, 0);
return $price;
}
// include the SOAP classes
require_once('nusoap.php');
// create the server object
$server = new soap_server;
// register the lookup service
$server->register('lookup');
// if the lookup fails, return an error
if $price == 0 {
$error = "Price lookup error";
}
if (isset($error)) {
$fault =
$server->fault('soap:Server','http://mydomain.com/booklookupscript.php',$err
or);
}
// send the result as a SOAP response over HTTP
$server->service($HTTP_RAW_POST_DATA);
?>
The first method I use is the soap_server constructor, which creates the server object that will be doing all the work for me. I assign that object to $server. Next is register, which tells the server what to do (in this case, to call the lookup() function). The method’s one parameter is the name of the function. There are other optional parameters that can be used to define the namespace and the SOAPAction information as specified in the SOAP specification, but those aren’t necessary for this example. The general syntax of the register method is:
register(name, in, out, namespace, SOAPAction, style)
The first parameter is the only mandatory one. in and out are arrays of input and output values; namespace and SOAPAction are used in accordance with the SOAP spec. Finally, style is used to indicate whether the data being sent is literal XML data (the default, and what I use in these examples) or RPC serialized application data.
So, the function is executed, and the returned value is passed to the server object. Then the service method returns a SOAP response to the client that initiated the request. The argument to the service method is $HTTP_RAW_POST_DATA.
Dealing with Errors
Because databases are not perfect, the script has a series of steps to catch errors. The lookup function contains three traps for different kinds of MySQL database errors. Each trap assigns an error identification string to the variable $error and returns that variable to the main function. Additionally, the main function tests the $price variable to ensure that it’s not set to zero, which would indicate a defective entry in the database.
If any one of these traps finds an error, NuSOAP’s fault method is called. This halts execution of the server script and returns the method’s parameters to the client as the string variable $fault. The syntax of the fault method is:
fault(faultcode, faultactor, faultstring, faultdetail)
The first two arguments are required, the latter two are optional. For the faultcode argument, a machine-readable fault code must be provided, as described in the SOAP spec. There are four predefined fault codes in the specification: VersionMismatch, MustUnderstand, Client, and Server. These must be given as qualified names in the namespace by prefixing them with SOAP-ENV:. A VersionMismatch error indicates incompatible namespaces. A MustUnderstand error is used when it comes across a mandatory header entry that it doesn’t understand. Client is used when the error lies in the message that was received from the client. And Server indicates a problem encountered during processing on the server, unaffiliated with the SOAP message per se. This latter code is what I used in the script when there’s a problem with the database lookup.
The faultactor argument should contain the URI where the problem originated. This is more important for transactions where numerous intermediaries are involved. In this example, I use the URI of the server script. (Note: the NuSOAP documentation implies that the faultactor element should be set to either “client” or “server.” The SOAP specification, however, says it should be a URI.)
faultstring and faultdetail are set aside for explaining the fault in human-readable language. faultstring should be a brief message indicating the nature of the problem, while faultdetail can go into more detail—it can even contain an array with specific itemized information about the fault. In my example, I pass the $error string to faultstring, and omit faultdetail.
A SOAP Client
Now I’ll write a client for an existing SOAP server, so you can see it in action. I’ll use XMethods’ Barnes & Noble Price Quote server, which acts a lot like the example server, above. It takes an ISBN as input and returns price data from Barnes & Noble.
The client script will need to send a request containing an ISBN and then parse the response. In this script, I use the soapclient class, its constructor, and call, which handles making a request and parsing the response all in one. The only method available on the server is GetPrice, which takes only one parameter, a string called isbn. It returns a floating-point variable called return.
// include the SOAP classes
require_once('nusoap.php');
// define parameter array (ISBN number)
$param = array('isbn'=>'0385503954');
// define path to server application
$serverpath ='http://services.xmethods.net:80/soap/servlet/rpcrouter';
//define method namespace
$namespace="urn:xmethods-BNPriceCheck";
// create client object
$client = new soapclient($serverpath);
// make the call
$price = $client->call('getPrice',$param,$namespace);
// if a fault occurred, output error info
if (isset($fault)) {
print "Error: ". $fault;
}
else if ($price == -1) {
print "The book is not in the database.";
} else {
// otherwise output the result
print "The price of book number ". $param[isbn] ." is $". $price;
}
// kill object
unset($client);
?>
The soapclient constructor takes a server URL as its argument. Having thus initialized the server object, I pass to the call method the name of the function I want (getPrice), the necessary parameters (the array containing the ISBN string to look up), and the required method namespace: urn:xmethods-BNPriceCheck.
The parameters for soapclient’s call method are: function name, parameter array, and three optional ones: namespace, SOAPAction, and an array of headers. The definition for the server will specify which, if any, of the optional parameters are necessary. The Barnes & Noble Price Quote server requires a method namespace definition (urn:xmethods-BNPriceCheck) but no SOAPAction or SOAP headers. Information about what this server offers and what it requires was gleaned from the server’s
listing on XMethods’ index of SOAP servers. (This particular server happens to be hosted by XMethods, but the index lists a wide variety of servers, regardless of host.)
The call method of the client performs the SOAP transaction and returns the content of the server’s response to the $price variable. The script checks for the presence of $fault, which the server returns if there was an error in the transaction. If the $fault variable is set, the script outputs the error information. If there isn’t an error, it checks to see if the price returned is -1, which indicates that the requested book was not found. Otherwise, the price data is printed.
A Closer Look at the Transaction
The actual XML message sent by the client to the server looks something like this:
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
0385503954


The Envelope tag contains pointers to the global namespace definitions. It also includes pointers to the SOAP envelope schema hosted on xmlsoap.org and to the W3C’s XML schema definition. These tell the server where it’s getting definitions for the various XML tags that it’s using. The XMLSchema class (which is, as of this writing, only experimental) can be used to work with aspects of the XML schema.
The schema definition is set automatically by NuSOAP to http://www.w3.org/2001/XMLSchema. If you wish to change this, you must set the $XMLSchemaVersion global variable:
$XMLSchemaVersion = 'http://www.my.org/MYSchema/';
Detailed discussion of the ins and outs of the W3C’s XML schema can be found in O’Reilly’s new book on the subject.
Within the Envelope tag is the Body tag, which contains the body of the message. Its attributes are determined by the parameters of the function call. The name of the remote method, the method namespace, and the actual content of the message—the ISBN string—are set by the client script. NuSOAP automatically detects the variable type and incorporates the type namespace (xsd:string) in the isbn tag. If a SOAPAction had been set in the script, that would appear as a SOAPAction HTTP header.
The encoding style is set by default to http://schemas.xmlsoap.org/soap/encoding/. This is pre-set by NuSOAP as the SOAP-ENC element of the public array called namespaces. To change it, simply include a line in your script like:
$namespaces[SOAP-ENC] = 'http://my.special.encoding';
The same technique can be used to change other namespace values, if necessary. The keys of the namespaces array are SOAP-ENV, xsd, xsi, SOAP-ENC, and si, corresponding to the namespace URIs for the envelope schema, the XML schema definition (equal to $XMLSchemaVersion), the XML schema instance, the encoding style, and the SOAP interoperability test URI, respectively. The default settings for these should not need to be changed under ordinary circumstances.
The server’s XML response to the request looks like this:
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
14.65


The envelope is pretty much the same as that of the request, though you’ll notice that the server uses an older XML schema than the client. The body is also similar: the method namespace and the encoding style are the same. The ns1 package tag has Response appended to its name now: . And where the request had an element called isbn, here the core of the response is called return, and the data type is specified as float. PHP is weakly typed, so NuSOAP assigns variable types automatically.
Conclusion
NuSOAP makes working with SOAP very easy by automatically handling the complexity, although it also provides a fair amount of access to the flexibility and nuance underneath. The call method of the soapclient class and the register method of the soap_server class do a lot of work that many other SOAP implementations make you do by hand. NuSOAP offers some access to the underlayer now, and will allow more as development proceeds.
To learn more about the details of working with SOAP, refer to the
SOAP specification and the API documentation that comes with NuSOAP. If you encounter a specific question about how NuSOAP handles SOAP transactions, it can be helpful to look at the nusoap.php file, which is clearly organized by class and decently commented. Going to the source, as it were, should answer most questions.

Wednesday, June 6, 2007

Confidence! - An Amazing Story


The business executive was deep in debt and could see no way out. Creditors were closing in on him. Suppliers were demanding payment. He sat on the park bench, head in hands, wondering if anything could save his company from bankruptcy. Suddenly an old man appeared before him. "I can see that something is troubling you," he said. After listening to the executive's woes, the old man said, "I believe I can help you." He asked the man his name, wrote out a check, and pushed it into his hand saying, "Take this money. Meet me here exactly one year from today, and you can pay me back at that time." Then he turned and disappeared as quickly as he had come. The business executive saw in his hand a check for $500,000, signed by John D. Rockefeller, then one of the richest men in the world! "I can erase my money worries in an instant!" he realized. But instead, the executive decided to put the uncashed check in his safe. Just knowing it was there might give him the strength to work out a way to save his business, he thought. With renewed optimism, he negotiated better deals and extended terms of payment. He closed several big sales. Within a few months, he was out of debt and making money once again. Exactly one year later, he returned to the park with the uncashed check. At the agreed-upon time, the old man appeared. But just as the executive was about to hand back the check and share his success story, a nurse came running up and grabbed the old man. "I'm so glad I caught him!" she cried. "I hope he hasn't been bothering you. He's always escaping from the rest home and telling people he's John D. Rockefeller." And she led the old man away by the arm. The astonished executive just stood there, stunned. All year long he'd been wheeling and dealing, buying and selling, c onvinced he had half a million dollars behind him. Suddenly, he realized that it wasn't the money, real or imagined, that had turned his life around. It was his newfound self-confidence that gave him the power to achieve anything he went after.
--
"If a drop of water falls in lake there is no identity.But if it falls on a leaf of lotus it shine like a pearl. So choose the best place where you would shine.. "

Wednesday, May 30, 2007

MS Excel - Shortcutsby Gokul.


ENTER

Complete a cell entry and move down in the selection

ALT+ENTER

Start a new line in the same cell

CTRL+ENTER

Fill the selected cell range with the current entry

SHIFT+ENTER

Complete a cell entry and move up in the selection

TAB

Complete a cell entry and move to the right in the selection

SHIFT+TAB

Complete a cell entry and move to the left in the selection

ESC

Cancel a cell entry

BACKSPACE

Delete the character to the left of the insertion point, or delete the selection

DELETE

Delete the character to the right of the insertion point, or delete the selection

CTRL+DELETE

Delete text to the end of the line

Arrow keys

Move one character up, down, left, or right

HOME

Move to the beginning of the line

F4 or CTRL+Y

Repeat the last action

SHIFT+F2

Edit a cell comment

CTRL+SHIFT+F3

Create names from row and column labels

CTRL+D

Fill down

CTRL+R

Fill to the right

BACKSPACE

Edit the active cell and then clear it, or delete the preceding character in the active cell as you edit cell contents

ENTER

Complete a cell entry

CTRL+SHIFT+ENTER

Enter a formula as an array formula

ESC

Cancel an entry in the cell or formula bar

CTRL+A

Display the Formula Palette after you type a function name in a formula

CTRL+SHIFT+A

Insert the argument names and parentheses for a function after you type a function name in a formula

CTRL+K

Insert a hyperlink

ENTER (in a cell with a hyperlink)

Activate a hyperlink

F2

Edit the active cell and position the insertion point at the end of the line

F3

Paste a defined name into a formula

SHIFT+F3

Paste a function into a formula

F9

Calculate all sheets in all open workbooks

CTRL+ALT+F9

Calculate all sheets in the active workbook

SHIFT+F9

Calculate the active worksheet

= (equal sign)

Start a formula

ALT+= (equal sign)

Insert the AutoSum formula

CTRL+; (semicolon)

Enter the date

CTRL+SHIFT+: (colon)

Enter the time

CTRL+SHIFT+" (quotation mark)

Copy the value from the cell above the active cell into the cell or the formula bar

CTRL+` (single left quotation mark)

Alternate between displaying cell values and displaying cell formulas

CTRL+' (apostrophe)

Copy a formula from the cell above the active cell into the cell or the formula bar

ALT+DOWN ARROW

Display the AutoComplete list

ALT+' (apostrophe)

Display the Style dialog box

CTRL+1

Display the Format Cells dialog box

CTRL+SHIFT+~

Apply the General number format

CTRL+SHIFT+$

Apply the Currency format with two decimal places (negative numbers appear in parentheses)

CTRL+SHIFT+%

Apply the Percentage format with no decimal places

CTRL+SHIFT+^

Apply the Exponential number format with two decimal places

CTRL+SHIFT+#

Apply the Date format with the day, month, and year

CTRL+SHIFT+@

Apply the Time format with the hour and minute, and indicate A.M. or P.M.

CTRL+SHIFT+!

Apply the Number format with two decimal places, thousands separator, and minus sign (–) for negative values

CTRL+SHIFT+&

Apply the outline border

CTRL+SHIFT+_

Remove outline borders

CTRL+B

Apply or remove bold formatting

CTRL+I

Apply or remove italic formatting

CTRL+U

Apply or remove an underline

CTRL+5

Apply or remove strikethrough formatting

CTRL+9

Hide rows

CTRL+SHIFT+( (opening parenthesis)


Unhide rows

CTRL+0 (zero)

Hide columns

CTRL+SHIFT+) (closing parenthesis)


Unhide columns

F10 or ALT

Make the menu bar active, or close a visible menu and submenu at the same time

TAB or SHIFT+TAB (when a toolbar is active)


Select the next or previous button or menu on the toolbar

CTRL+TAB or CTRL+SHIFT+TAB (when a toolbar is active)


Select the next or previous toolbar

ENTER


SHIFT+F10

Show a shortcut menu

ALT+SPACEBAR

Show the program icon menu (on the program title bar)



Common Computer-related Eye Problems and Their Solutions

Common Computer-related Eye Problems and Their Solutions
Problem Causes Treatment
Blurred vision Incorrect glasses/spectacles or contact lens prescription Eye examination and correction of refractive error from optometrists/ophthalmologist

Decreased blink frequency Increase the blink rate. Make conscious effort to blink when you work on the computer. Every once in a while gaze way from the computer into the distant or a blank space.

An accommodative spasm Gaze away from the monitor every 15 minutes.

Tear film abnormality Artificial tear drops may be prescribed by the eye specialist.
Aching, burning and stinging eyes High-velocity/air-conditioning currents on workstation Use deflector.

Lid or eye inflammation Eye examination and treatment. Avoid rubbing your eyes. When tired, it is better to take a walk or wash your eyes.

Improper spectacles or contact lens prescription Eye examination
Headache Poor monitor resolution Use a large (but not over 48cm), high –quality monitor or increase the font size. The comfortable refresh rate is 70 hertz.

Cluttered viewing Clean it up.
Neck, shoulder and back pain Poor workstation ergonomics Improve posture. Move away. Usual working distance from the monitor is 45.7 to 66 cm (18 to 26 inches). The eyes need to focus and refocus in space around the monitor. The constant focusing effort induces tiredness of eyes.

Insufficient back support Improve chair. Lower lumbar support which supports your buttocks/hips will cut down the strain by about half.

Poor posture-leaning or tilting head back to see/focus on the screen Eye examination, improvement in posture and chair, and correct placement of the typing material.

It is advisable to use clips to position the material next to the monitor. This tends to cut down repeated refocusing efforts and hence eyestrain

Games

Hi all,
Good to play Flash games here
http://www.cartoonnetwork.com/games/

--
"If a drop of water falls in lake there is no identity.But if it falls on a leaf of lotus it shine like a pearl. So choose the best place where you would shine.. "

Tuesday, May 29, 2007

Life is short

Image hosting by TinyPic

There is very instructive incident involving the life of Alexander, the great Greek king.

Alexander, after conquering many kingdoms, was returning home. On the way, he fell ill and it took him to his death bed. With death staring him in his face, Alexander realized how his conquests, his great army, his sharp sword and all his wealth were of no consequence.

He now longed to reach home to see his mother's face and bid her his last adieu. But, he had to accept the fact that his sinking health would not permit Him to reach his distant homeland. So, the mighty conqueror lay prostrate and pale, helplessly waiting to breathe his last. He called his generals and said, "I will depart from this world soon,

I have three wishes, please carry them out without fail." With tears flowing down
Their cheeks, the generals agreed to abide by their king's last wishes.

"My first desire is that,” said Alexander, "My physicians alone must carry my coffin." After a pause, he continued, "Secondly, I desire that when my coffin is being carried to the grave, the path leading to the graveyard be strewn with gold, silver and precious stones which I have collected in my treasury.

" The king felt exhausted after saying this. He took a minute's rest and continued. "My third and last wish is that both my hands be kept dangling out of my coffin."

The people who had gathered there wondered at the king's strange wishes. But no one dare bring the question to their lips. Alexander's favorite general kissed his hand and pressed them to his heart. "O king, we assure you that your wishes will all be fulfilled.

But tell us why do you make such strange wishes?"

At this Alexander took a deep breath and said: "I would like the world to know of the three lessons I have just learnt. I want my physicians to carry my coffin because people should realize that no doctor can really cure any body. They are powerless and cannot save a person from the clutches of death. So let not people take life for granted.

The second wish of strewing gold, silver and other riches on the way to the graveyard is to tell

People that not even a fraction of gold will come with me. I spent all my life earning riches but cannot take anything with me. Let people realize that it is a sheer waste of time to chase wealth.
And about my third wish of having my hands dangling out of the coffin, I wish people to know that I came empty handed into this world and empty handed I go out of this world."

With these words, the king closed his eyes. Soon he let death conquer him and breathed his last. . . . .

Monday, May 28, 2007

What's new in PHP V5.2

I read this article in the developer works from IBM, nice one from them, posting it here for the others need.

What's new in PHP V5.2, Part 1: Using the new memory manager

Track and monitor PHP memory use like an uber-nerd



Level: Intermediate

Tracy Peterson (tracy@tracypeterson.com), Freelance Writer, Consultant

13 Mar 2007

In Part 1 of this "What's new in PHP V5.2" series, learn how to use the new memory manager introduced in PHP V5.2 and become proficient at memory usage tracking and monitoring. This will enable you to more use memory in PHP V5.2 more efficiently.

PHP V5.2: In the beginning

In November 2006, PHP V5.2 was released with many new features and bug fixes. It obsoletes the 5.1 release and is a recommended upgrade for any PHP V5 users. My favorite lab environment -- Windows®, Apache, MySQL, PHP (WAMP) -- is rolled into a new package for V5.2 already (see Resources). You will find an application there that will set up PHP V5.2, MySQL, and Apache on a Windows® XP or 2003 machine. It's a piece of cake to install, has lots of nice little management goodies, and I recommend it wholeheartedly.

While this is the easiest package for Windows users, you need to add the following when configuring PHP on Linux: --memory-limit-enabled (in addition to any other options appropriate for your server). Under Windows, however, there is a workaround function provided.

There are many improvements that have taken place in PHP V5.2, and one critical area is that of memory management. The exact quote from README.ZEND_MM states: "The goal of the new memory manager (PHP5.2 and later) is reducing memory allocation overhead and speeding up memory management."

Here are some of the key items from the V5.2 release notes:

  • Removed unnecessary --disable-zend-memory-manager configure option
  • Added --enable-malloc-mm configure option, which is enabled by default in debug builds to allow using internal and external memory debuggers
  • Allows tweaking the memory manager with ZEND_MM_MEM_TYPE and ZEND_MM_SEG_SIZE environment variables

To understand the implications of these new features, we need to delve into the fine art of memory management a bit and consider why allocation overhead and speed are a big deal.


Why memory management?

One of the fastest-developing technologies in computing is memory and data storage, which are driven by the constant need for increases in speed and storage size. Early computers used cards as memory before moving to chip technology. Can you imagine working on a computer with only 1 KB of RAM? Many early computer programmers did. These pioneers realized very rapidly that to work within the restraints of the technology, they would have to be diligent to avoid overloading their systems with frivolous commands.

As PHP developers, we live in a much more convenient world to code in than our colleagues who code in C++ or other stricter languages. In our world, we do not have to concern ourselves with the handling of system memory because PHP handles that for us. In the rest of the programming world, however, responsible coders use various functions to ensure that executed commands do not overwrite some other program data -- thus, crippling that running program.

Memory management is usually handled by requests from the coder to allocate and release blocks of memory. Allocated blocks can hold data of any type, and this process blocks off a certain amount of memory for just that data and gives the program a method of addressing this data for when it needs to be accessed for operations. The program is expected to release allocated memory when it has completed any operations, and let the system and other programs use that memory. When a program does not release the memory back to the system, it is called a leak.

Leaks are a normal problem with any running program, and a certain amount is usually acceptable, especially when we know a running program will terminate soon and release all of any memory allocated to it by default.

With programs you run and terminate arbitrarily, like almost all client applications, this is the case. Server applications are expected to run indefinitely without termination or restart, making memory management absolutely vital to server daemon programming. Even a small leak would eventually grow into a system-debilitating problem on a long-running program as memory blocks are used and never released.



Long-term thinking

There are many potential uses for a persistent server daemon written in PHP, as with any language. But when we begin to use PHP for these purposes, we must also consider our memory usage.

Scripts that parse a great deal of data or which may be hiding an infinite loop have a tendency to consume large amounts of memory. Obviously, once the memory is exhausted, the performance of the server decreases, so we must also pay attention to how much memory we're using when we execute our scripts. While we can simply watch the amount of memory used by a script by turning the system monitor on, it will not tell us anything more useful than the status of the entire system memory. Sometimes we need to do a bit more than that to help us troubleshoot or optimize. Sometimes we just need more detail.

One way to get transparency into what our script is doing is to use an internal or external debugger. An internal debugger is one that appears to be the same process executing the script. Debuggers that are a separate process from the perspective of the OS are external. Memory analysis using a debugger is similar in either case, but the memory is accessed in different ways. Internally, a debugger has direct access to the same memory space as the running process, while an external debugger will access the memory via a socket.

There are many methods and available debugging servers (external) and libraries (internal) you can use to aid your development. In order to prepare your PHP installation for debugging, you can use the newly provided --enable-malloc-mm, which is enabled by default in a DEBUG build. This makes the environment variable USE_ZEND_ALLOC available to allow selection of malloc or emalloc memory allocations at runtime. Using malloc-type memory allocations will allow external debuggers to observe memory use while emalloc allocations will use the Zend memory manager abstraction, requiring internal debugging.



Memory management functions in PHP

In addition to making the memory manager more flexible and transparent, PHP V5.2 provides a new parameter for memory_get_usage() and memory_get_peak_usage(), which allow the viewing of the amount of used memory. The new Boolean mentioned in the notes is real_size. By invoking the function memory_get_usage($real); where $real = true, the result will be the real size of memory allocated from the system, including the memory-manager overhead, at the moment of invocation. Without the flag set, the data returned would be only the memory used within the running script, minus the memory-manager overhead.

memory_get_usage() and memory_get_peak_usage() differ in that the latter returns the peak memory usage so far for the running process that invokes it while the first only returns the usage at the moment of execution.

For memory_get_usage(), php.net provides the code snippet in Listing 1.


Listing 1. A memory_get_usage() example


In this simple example, we first echo the results of a straight up invocation of memory_get_usage(), which by the code annotation seems to have had a common result of 36640 bytes on the author's system. We then load up $a with 4,242 copies of "Hello" and run the function again. The output of this simple usage can be seen in Figure 1.


Figure 1. Example output of memory_get_usage()
Example output of memory_get_usage()

There is no example of memory_get_peak_usage() as the two are so similar. The syntax is identical. For the example code in Listing 1, there would be only one result, however, which is the peak memory usage at that moment. Let's take a look in Listing 2.


Listing 2. A memory_get_peak_usage() example


The code in Listing 2 is identical to Figure 1, but memory_get_usage() has been swapped for memory_get_peak_usage(). Nothing much changes in output until we populate $a with the 4242 iterations of "Hello." Our memory jumps to 57960, representing our peak so far. When we check the memory usage peak, we get the highest value so far, so every further invocation will result in 57960 until we do something to use more memory than we did with $a (see Figure 2).


Figure 2. Example output of memory_get_peak_usage()
Example output of memory_get_peak_usage()





Limiting memory usage

One way to make sure we do not overtax the server we are hosting our application on is to limit the amount of memory used by any scripts executed by PHP. This isn't something we should have to do at all, but as PHP is a loosely typed language and is parsed at runtime, we sometimes get scripts that are poorly written unleashed upon our production applications. These scripts might execute a loop, or perhaps open a long list of files, forgetting to close the current file before opening a new one. Whatever the case, a poorly written script can end up chewing up a ton of memory before you know it.

In PHP.INI, you can use the configuration parameter memory_limit to specify the maximum amount of memory any script is able to run on the system. This is not a specific change to V5.2, but any discussion of the memory manager and its uses bears at least a quick look at this feature. It also leads me nicely to the last new features of the memory manager: environment variables.



Tweaking the memory manager

Finally, what would programming be without being able to be a perfectionist and get it exactly right for your purposes? The new environment variables ZEND_MM_MEM_TYPE and ZEND_MM_SEG_SIZE allow you to do just that.

When the memory manager allocates large memory blocks, it does so in predetermined sizes, listed in the variable ZEND_MM_SEG_SIZE. The default size of these memory segments is 256 KB per block, but you can adjust these to suit your particular needs. For instance, if you were aware that the operations in one of your most common scripts was causing a large amount of wasted memory, you could adjust this size to more closely match the needs of the script, reducing the amount of memory allocated but remaining empty. In the right conditions, this kind of careful configuration tweaking can make a huge difference.



Retrieving memory usage on Windows

If you have a pre-built PHP Windows binary without the --enable-memory-limit option on when it was built, you need to go through this section before moving on. For Linux®, build PHP with the --enable-memory-limit option on when you configure your PHP build.

To retrieve memory usage using Windows binaries, create the following function.


Listing 3. Getting memory usage under Windows

Save this in a file called function.php. Now you only have to include this file in scripts you wish to use it in.


PHP related informations

Hi all,
i would like to keep posting some usefull informations here so that everyone gets benifited

I recently read a article that helps to do a load testing of our web apps
its
http://www.joedog.org/JoeDog/Siege
This one is really nice

Tuesday, January 9, 2007

My First Blog

Hi all,

This is my first blog.