January 16th, 2013, 12:30 AM
When to use include, include_once, require, require_once, readfile...
I'd like to understand the best options to use in my scenario and whether to use http:// in the call or not.
I have Apache web servers configured with Reverse Proxying in place.
Web Server as the front end where the code with call is accessed.
I have proxied servers (backend) behind this that the call needs to execute other code. This code does the hard work.
I will need to be able to pass session/form information from front end to backend systems as part of the processing that the backend runs.
I can either call the backend code via http:// or via /revproxypath/to/code type calls. I expect the later will require more frontend apache processing than the http:// format.
What is the most appropriate call to use to execute the code?
What is the likely security issues relating to this?
What are the performance impacts of choosing one over the other?
Thanks kindly for all responses!
January 16th, 2013, 02:53 AM
The include() and require() functions are almost the same, except that when an error occurs, the include() function will only show a warning, while the require() function will show a fatal error and completely terminate the script.
Adding _once to the function will have PHP check if the file was already included so it won't be included again.
I think using a relative path is better and personally use it all the time, but I'm not sure if the reverse proxying has a performance impact.
January 16th, 2013, 09:54 AM
include and require will execute the contents of the file.
readfile will output the contents of the file.
If you use http in the path, then an http request will be issued to that URL and the 'contents' of the file will be whatever that http request returns.
You should almost never use a URL with include or require.
If you want to execute code on a different server you would want to use readfile or file_get_contents with a URL.
January 17th, 2013, 01:48 AM
For my current purpose it is looking like readfile is the best approach. And using direct HTTP URL calls as opposed to using the Apache reverse proxy path.