Hello,
I have a general question about performance of PHP scripts:
In some scripts, I have a mix of straight HTML output and usage of PHP functions.
There are two ways to do:
1. PHP only: everything is PHP code, thus I need to put every HTML output int o echo(); statement, even if there are no $variables or other PHP content.
Example:
<?
$var1=any_function($input1);
$var2=any_other_function($input2);
echo "<table>\n";
echo "<tr><th>Col1</th><th>Col2</th></tr>\n";
echo "<tr><td>$var1</td><td>$var2</td></tr>\n";
...
?>
- I use straight HTML where I want to print unvarying text, and I use PHP sections only for variable data.
Example:
<?
$var1=any_function($input1);
$var2=any_other_function($input2);
?>
<table>
<tr><th>Col1</th><th>Col2</th></tr>
<tr><td><?$var1?></td><td><?$var2?></td></tr>
...
Which ways of both is the fastest ?
Is it faster to have the PHP-processor do all the job with the echo()-statement, or doesn't switching between PHP-Code and Non-PHP-code matter in performance?
Is echo() possibly a resource-consuming statement which I should abandon to get a better performance?
Or are both ways basically equivalent?
As I have no experience with performance testing, benchmarking, etc. I don't have any idea how to find an answer to this, or how to build a test scenario.
Hint: I generally work in a LAMP environment (Linux, Apache, Mysql, PHP)
Any suggestions are welcome.
Have a nice day,
JJ Mouris