PHP Interpreter load
A few questions for people who understand the PHP interpreter well.
- Does the number of opening descriptors affect the script execution speed? I.e., the file contains a mixture of HTML markup and PHP code, and will it significantly affect performance if we open and close
<? ?>
on each line?
This:
<?
if( $val > 0 ) {
echo 'yes';
}
else {
echo 'no';
}
?>
Or
<? if( $val > 0 ) { ?>
<? echo 'yes'; ?>
<? } ?>
<? else { ?>
<? echo 'no'; ?>
<? } ?>
- Is there a difference in the speed of execution by the interpreter, classical syntax and alternative syntax?
I.e. between such:
<?
if( $val > 0 ) {
echo 'yes';
}
else {
echo 'no';
}
?>
And so:
<?
if( $val > 0 ):
echo 'yes';
else:
echo 'no';
endif;
?>
Options.
- Which of the options for the output of a variable and the results of a function uses less resources, if at all, there is a difference?
This:
<? echo '$value'; ?>
Or this one:
<?=$value?>
4
2 answers
<?
$e = '';
$st = microtime(1);
for ($i = 0; $i < 1000000; $i++) {
if (1 > 0) {
echo $e;
} else echo $e;
}
echo '<br />'.(microtime(1)-$st);
$st = microtime(1);
for ($i = 0; $i < 1000000; $i++) { ?>
<? if (1 > 0) { ?>
<? echo $e; ?>
<? } else { ?>
<? echo $e; ?>
<? } ?>
<? }
echo '<br />'.(microtime(1)-$st);
echo '<hr />';
$st = microtime(1);
for ($i = 0; $i < 1000000; $i++) { ?>
<? if (1 > 0) { ?>
<?=$e?>
<? } else { ?>
<?=$e?>
<? } ?>
<? }
echo '<br />'.(microtime(1)-$st);
$st = microtime(1);
for ($i = 0; $i < 1000000; $i++) { ?>
<? if (1 > 0) { ?>
<? echo $e; ?>
<? } else { ?>
<? echo $e; ?>
<? } ?>
<? }
echo '<br />'.(microtime(1)-$st);
echo '<hr />';
?>
Result:
0.08100700378418
2.4613921642303
----
3.0508909225464
2.4576618671417
The last 2 changed from "1.5 / 6" to "4/1", so it is more likely the same. And here is the first pair-talking)
UPDATE, syntax
<?
$e = '';
$st = microtime(1);
for ($i = 0; $i < 1000000; $i++) {
if (1 > 0) {
echo $e;
} else echo $e;
}
echo '<br />'.(microtime(1)-$st);
$st = microtime(1);
for ($i = 0; $i < 1000000; $i++) {
if (1 > 0):
echo $e;
else:
echo $e;
endif;
}
echo '<br />'.(microtime(1)-$st);
echo '<hr />';
?>
0.089139938354492
0.082063913345337
3
Author: Sh4dow, 2012-02-24 16:07:35
In my opinion, this is "saving on matches" and it is unlikely that anyone will give an accurate and correct answer
4
Author: Maksym Prus, 2012-02-24 14:41:58