note 9982 deleted from function.print by jimw
| From: | jimw@php.net | Date: | Fri, 14 Dec 2001 20:21:51 +0000 |
| Subject: | note 9982 deleted from function.print by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22738@lists.php.net to get a copy of this message | ||
A small note regarding the use of HERE documents (print <<<EOF) vs. a multi-line echo.
I've just put together a small library of functions whose sole purpose is to spit out chunks of
html to construct a page. Using ab (apache bench), I made 1,000 queries on on the page using HERE
documents, then repeated the test using a multi-line echo (e.g. echo '
<html>
</html>
';)
And what I found was rather interesting. Using HERE docs, I was able to respond to ~68
requests/second at a rate of 1032 kb/s. Using a multi-line echo, I was able to serve 80
requests/second at a rate of 1205 kb/s (this is over a two-machine, full-duplex 100bT LAN). There
was no variable interpolation performed in these functions--it was strictly spitting out text.
So, if you're wanting to spit out lots of text as fast as possible and that text has no
variables that need to be interpolated, use the multi-line echo with single-ticks. If you have
variables in the body that need to be interpolated and you don't mind backslashing all quotes
in the body, you can use a multi-line echo with double-quotes. As a last resort, if you don't
want to bother with backslashing your quotes and/or aren't concerned about speed, just go with
the heredocs.