Has any one done comparison between the following statements: <?php echo 'This is all the html content printout with php variables, like i = ' . $i ; ?> PHP: versus <?php echo <<<EOQ This is all the html content printout with php variables, like i = $i EOQ; ?> PHP: I find using "echo <<<EOQ " very convenient but was wondering if it has some speed bumps compared to simple echo? I searched on net but couldn't come up quickly with reasonable answer.. So you tell me!!
echo "string" is much faster ... as compile time for this statement is less than the <<<EOQ EOQ; ...as in case of EOQ it needs to do lot of tracking for escape sequences... Let me know members if i am correct .. as both methods are useful .... but i prefer to use echo "";
I think it's better to use ' ' instead of ", because it doesn't have to parse the content, it simply shows it.
It really makes little difference, all three methods are just as good as each other, any speed gains over each other would be minimal.
Heredoc was slow in older versions of PHP. I think its been fixed in recent versions. There is no difference at all between single and double quotes. There IS a difference between: echo "one" . " " . "two"; PHP: and echo "one", " ", "two"; PHP: Notice the use of commas instead of concatenation. If you care about performance, use an opcode cache. This stuff isn't worth worrying about.
Of course there is a difference. Do you not think that it's faster when the parser doesn't have to go through a string trying to find variables it has to parse? If you have single quotes it just gets displayed as is.
A question along these lines came up at Vancouver PHP Conference earlier this month and core developers there said this is one of the last things to consider when speeding up apps. The first thing to do is run your PHP code throughthe Callgrind module in Valgrind. This will help you figure out where your code is spending most of its time, pointing you in the correct direction for optimizing code.
Recognizing strings is the job of the scanner, not the parser. The factors that influence its performance are not intuitive. I've traced the scanning code looking into this particular issue. I'm guessing you haven't. There is nothing to see here. Move along. If you really want to have an impact on performance, use this tool.