Jump to content

Recommended Posts

I apologize if this question comes off a bit amateur but is it possible to do a PHP include as it would display and not as it would function without using the absolute location of the PHP file?  It would obviously ease the load on my server to use relative location for all of my includes but this is one obstacle I'm not sure I can overcome.

 

Any help would be greatly appreciated.

In my short time working with PHP, what I've noticed is that if you place an include with an absolute link, the code will appear as it would display.  For example, if I have a script that pulls the titles of songs off of my server and displays them at random, an absolute include would simply display the song title because it would only use what would be displayed to the user.  But if I did it relatively, it would add the entire script to the page because it's pulling the file locally.

 

But I don't want to use absolute links.  Our server seems to struggle resolving the address.

No. A relative URL only has meaning in a browser because a browser will take the URL of the current page and append a relative URL to it, forming the absolute URL that is needed in a http request.

 

The syntax for a relative URL in an include statement would be treated as a file system path.

 

When an include uses a URL, you only receive the content that is output by the included page. This does not include the php code and it does not share variables, in addition to taking the extra time needed for the extra http request to be serviced by the web server.

 

Including file through the file system, either using absolute file system paths or relative file system paths, is much faster and is how the include statement is intended to be used.

File system access takes at most a few 10's of milliseconds for each include statement. Using a URL will take a minimum in the range of 200-500 milliseconds for each include statement, for the http request to be serviced and the results to be returned.

 

You should only use a URL because you must, not because it is easiest, because it is not the fastest and the performance of your web site will suffer as a result.

Right.  If it were up to me, I wouldn't use URL's at all because it is very clear there is a strain on the server, but there doesn't seem to be an alternative to including what is only being output by the PHP file.  If there is an alternative, I guess that's what I'm looking for in this thread.

When you include through the file system and the content/php in the included file is parsed/executed along with the main file's content/php, you get the same combined results. This is how everyone includes headers, menus, forms, general content, footers... Why is this somehow not what you want?

 

Also, unless you have unlimited monthly bandwidth, including using a URL consumes your bandwidth two times. Once when the include gets the content and again when that content is sent to the browser.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.