Variable Visions

Articles PHP PHP-SPEED-TEST


tutorials - PHP and Web-Development.

PHP SPEED TEST: include vs. require vs. file_get_contents vs. readfile

Published Mon. Dec. 31, 2012


I use php includes to pull more php into another  file or to create a template where included content contains more php scripts. I use require_once to include MySQL connection code in securely.

http://www.variablevisions.com/articles/Make-your-own-CMS

But, what if the content you want to pull in is on a DIFFERENT SERVER? I had a project where there were two sites…an old and a new. The new site was using a jsp templating structure in NetSuite and the old site was a hardcoded and used html files without any templating structure.
At first, I used file_get_contents to pull in content (pieces of the html template that DID NOT CONTAIN php code…just html) from the new site…into the old….cool!
That, way…when I want to update the header on both sites, I just update one template bit of html and the jsp template on the new site uses it, and the file_get_contents is used on the old static pages to pull in the same template snippet the new site does (which is on the new sites server)
The old site’s file were NOT php  files but .html files…so how did I process php on html pages?

Read here http://www.variablevisions.com/articles/Process-PHP-on-an-HTML-page

There is some debate regarding which is better for speed…file_get_contents or readfile. My speed test showed negligible differences.