#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    When to use include, include_once, require, require_once, readfile...


    Hi,

    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!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    106
    Rep Power
    51
    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.
    Post to Facebook using a Nokia 3310
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    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.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    Thanks all,

    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.

    Cheers

IMN logo majestic logo threadwatch logo seochat tools logo