Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Oct 2008, 09:25 PM   #1
Warrior Member
War Room Member
 
Amirol's Avatar
 
Join Date: 2007
Posts: 82
Thanks: 21
Thanked 10 Times in 10 Posts
Default
Reading a Remote File Using PHP - Is it good or not?
Share on: 
fb share twitter share gplus share more share

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.

$ 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 offline  
Unread 21st Oct 2008, 11:26 PM   #2
White Hat Marketer
War Room Member
 
Dan Grossman's Avatar
 
Join Date: 2007
Location: Montgomeryville, PA
Posts: 1,546
Thanks: 77
Thanked 775 Times in 267 Posts
Default
Re: Reading a Remote File Using PHP - Is it good or not?
Share on: 
fb share twitter share gplus share more share

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.

Improvely: Built to track, test and optimize your marketing.

[SIGPIC][/SIGPIC]
Dan Grossman is offline  
Unread 23rd Oct 2008, 06:18 AM   #3
Warrior Member
War Room Member
 
Amirol's Avatar
 
Join Date: 2007
Posts: 82
Thanks: 21
Thanked 10 Times in 10 Posts
Default
Re: Reading a Remote File Using PHP - Is it good or not?
Share on: 
fb share twitter share gplus share more share

Thanks guys!

I'll test it out.
Amirol is offline  
Unread 23rd Oct 2008, 11:16 AM   #4
<LunLun />
War Room Member
 
Sergiu FUNIERU's Avatar
 
Join Date: 2008
Location: ~Virtual = Valea Caselor (Romania)
Posts: 419
Thanks: 115
Thanked 42 Times in 33 Posts
Blog Entries: 15
Default
Re: Reading a Remote File Using PHP - Is it good or not?
Share on: 
fb share twitter share gplus share more share

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  
Unread 23rd Oct 2008, 11:19 AM   #5
Graham Clarke
 
Join Date: 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: Reading a Remote File Using PHP - Is it good or not?
Share on: 
fb share twitter share gplus share more share

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  
Unread 23rd Oct 2008, 11:33 AM   #6
White Hat Marketer
War Room Member
 
Dan Grossman's Avatar
 
Join Date: 2007
Location: Montgomeryville, PA
Posts: 1,546
Thanks: 77
Thanked 775 Times in 267 Posts
Default
Re: Reading a Remote File Using PHP - Is it good or not?
Share on: 
fb share twitter share gplus share more share

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.

Improvely: Built to track, test and optimize your marketing.

[SIGPIC][/SIGPIC]
Dan Grossman is offline  
Unread 23rd Oct 2008, 11:39 AM   #7
<LunLun />
War Room Member
 
Sergiu FUNIERU's Avatar
 
Join Date: 2008
Location: ~Virtual = Valea Caselor (Romania)
Posts: 419
Thanks: 115
Thanked 42 Times in 33 Posts
Blog Entries: 15
Default
Re: Reading a Remote File Using PHP - Is it good or not?
Share on: 
fb share twitter share gplus share more share

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  
Unread 7th Nov 2008, 08:25 AM   #8
Warrior Member
War Room Member
 
Amirol's Avatar
 
Join Date: 2007
Posts: 82
Thanks: 21
Thanked 10 Times in 10 Posts
Default
Re: Reading a Remote File Using PHP - Is it good or not?
Share on: 
fb share twitter share gplus share more share

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 offline  
Closed Thread


Bookmarks

Tags
file, good, php, reading, remote


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 09:13 AM.