Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 10-21-2008, 10:25 PM   #1
Warrior Member
War Room Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 11
Thanked 5 Times in 5 Posts
Social Networking View Member's Twitter Profile 
Default Reading a Remote File Using PHP - Is it good or not?

Hi guys... I need your opinion about this topic.

I want to use the code below to include a specific file (ex: terms.php) to all my web pages located on various servers.

Quote:
$ content = file_get_contents('http://www.google.com/');
if ($ content !== false) {
// my echo here
} else {
// an error happened
}
Case:

Let say I have 3 servers, A, B and C.

Then I have 3 different sites in server A, B and C.

Each sites will have same navigation at the end of the page which I will create a navigation.php file and place it on server A.

Then, I will use those code to get the navigation.php content from server A to appear on all of my web pages (in server A, B and C).

So, what I do want to know is this method is really effective? Does this method will affect my web pages loading time?

I used to use ssi method but I want to know is this method is more efective than ssi?

The reason of using this method is, I want to easily change some of the content especially for the terms/navigation/offers in all my webpages.

Thank you for your reply.

-A.Z
Amirol is online now   Reply With Quote
Old 10-22-2008, 12:26 AM   #2
Happily Self-Employed
War Room Member
 
Dan Grossman's Avatar
 
Join Date: Jan 2007
Location: Philadelphia, PA
Posts: 797
Thanks: 16
Thanked 345 Times in 53 Posts
Social Networking View Member's Twitter Profile 
Default Re: Reading a Remote File Using PHP - Is it good or not?

Nothing wrong with this, but I highly suggest building a caching mechanism so that the remote request doesn't happen on every page load. It both slows down response time and wastes your bandwidth.

Easy cache system is to create a text file to store the cached document, and if it's older than X minutes, download the page again and write it back to the file. Otherwise, just read the contents of the local file, which is essentially instant.

filemtime() gives you the modification time of the file.

Dan Grossman is offline   Reply With Quote
Old 10-23-2008, 07:18 AM   #3
Warrior Member
War Room Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 11
Thanked 5 Times in 5 Posts
Social Networking View Member's Twitter Profile 
Default Re: Reading a Remote File Using PHP - Is it good or not?

Thanks guys!

I'll test it out.
Amirol is online now   Reply With Quote
Old 10-23-2008, 12:16 PM   #4
<LunLun />
War Room Member
 
Sergiu FUNIERU's Avatar
 
Join Date: May 2008
Location: ~Virtual = Valea Caselor (Romania)
Posts: 377
Blog Entries: 15
Thanks: 109
Thanked 30 Times in 24 Posts
Social Networking View Member's Twitter Profile 
Contact Info
Send a message via Skype™ to Sergiu FUNIERU
Default Re: Reading a Remote File Using PHP - Is it good or not?

If I understand well, you want to include a remote php file. This is not possible, because you'll include the parsed file and not the original one.
That is, if you try:
$ content = file_get_contents('http://server.a/test.php');
you'll not include the test.php, but the parsed test.php, which is totally different.

The only exception is if test.php is actually a static file, in which case you don't need the php extension.

Sergiu FUNIERU is offline   Reply With Quote
Old 10-23-2008, 12:19 PM   #5
Graham Clarke
 
Join Date: Oct 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Contact Info
Send a message via Skype™ to gdclarke
Default Re: Reading a Remote File Using PHP - Is it good or not?

Be careful how you set the URL in your PHP code. If this is a variable, you'll need to make sure the proper precautions.

Graham

53 Technology

SimplWeb - hosted Joomla!
gdclarke is offline   Reply With Quote
Old 10-23-2008, 12:33 PM   #6
Happily Self-Employed
War Room Member
 
Dan Grossman's Avatar
 
Join Date: Jan 2007
Location: Philadelphia, PA
Posts: 797
Thanks: 16
Thanked 345 Times in 53 Posts
Social Networking View Member's Twitter Profile 
Default Re: Reading a Remote File Using PHP - Is it good or not?

Quote:
Originally Posted by ForumJoiner View Post
If I understand well, you want to include a remote php file. This is not possible, because you'll include the parsed file and not the original one.
That is, if you try:
$ content = file_get_contents('http://server.a/test.php');
you'll not include the test.php, but the parsed test.php, which is totally different.

The only exception is if test.php is actually a static file, in which case you don't need the php extension.
He said it was navigation, HTML links, so the parsed output is all he needs. As long as navigation.php is self-contained, no it does not have to be a static file at all.

Dan Grossman is offline   Reply With Quote
Old 10-23-2008, 12:39 PM   #7
<LunLun />
War Room Member
 
Sergiu FUNIERU's Avatar
 
Join Date: May 2008
Location: ~Virtual = Valea Caselor (Romania)
Posts: 377
Blog Entries: 15
Thanks: 109
Thanked 30 Times in 24 Posts
Social Networking View Member's Twitter Profile 
Contact Info
Send a message via Skype™ to Sergiu FUNIERU
Default Re: Reading a Remote File Using PHP - Is it good or not?

Quote:
Each sites will have same navigation at the end of the page which I will create a navigation.php file and place it on server A.
Well, I understand from here that the navigation.php will take care of the navigation links. If the navigation links are different for each server (like pagination, for instance), the content of navigation.php will be dynamic. If he wants only static, then I agree entirely with you.

Sergiu FUNIERU is offline   Reply With Quote
Old 11-07-2008, 08:25 AM   #8
Warrior Member
War Room Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 11
Thanked 5 Times in 5 Posts
Social Networking View Member's Twitter Profile 
Default Re: Reading a Remote File Using PHP - Is it good or not?

Hi guys,

Thank you for your response.

I just use include method instead of file_get_contents. (I feel my pages load a bit slow using file_get_contents).

Anyway, thanks again!
Amirol is online now   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
file, good, php, reading, remote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 06:35 AM.