Web Hosting Talk







View Full Version : Stupid PHP Include


SVS Morph
01-24-2004, 10:47 AM
On one of my sites I'm trying to include news from our forums. Here is a copy of the code in my index.php file.
<?php
include("/home/in/public_html/Inserts/upper.html");
include("http://www.iwnation.com/Forums/ssi.php?a=news&show=5");
include("/home/in/public_html/Inserts/lower.html");
?>
Unfortunately it takes a long time, often two days, for the news to show up. Any reason why this is, and any reason how to fix it??

sangeetha
01-24-2004, 11:12 AM
The only reason why your includes are slow is because of the huge images that the url has.

It takes ages to load on a regular browser.

To always test what you put in an include, you first need to check the link in a browser. If it is slow in a browser, chances are it will be slow in the include too.

SVS Morph
01-24-2004, 12:35 PM
But it's not just because of that, the server has been decently slow the past two days but the news has been messed for much longer.

CyberAlien
01-24-2004, 01:19 PM
use readfile() instead of include()

Rich2k
01-24-2004, 05:06 PM
Yes you shouldn't use include or require for remote files. Gives more problems than it solves.

SEATi
01-24-2004, 09:58 PM
You can also use fread...

Rich2k
01-25-2004, 06:05 AM
fopen with fread I have discovered some bugs with reading remote files. It's much more reliable to use fsockopen

mg-
01-25-2004, 03:17 PM
Originally posted by Rich2k
fopen with fread I have discovered some bugs with reading remote files. It's much more reliable to use fsockopen

fopen/fread seems to work for my nicely.. I had to make a bot that parsed alil over 100,000 pages. Took a day because it was remote... but it worked! :D

SEATi
01-25-2004, 03:31 PM
fsockopen works fine, but it will also include headers and almost every http variable. With fopen and fread you can receive only the needed data.

CyberAlien
01-25-2004, 03:48 PM
then use something like this to split header and data:

list($header, $data) = explode("\r\n\r\n", $str, 2);

SVS Morph
01-25-2004, 05:44 PM
readfile() seems to work :)

mg-
01-25-2004, 08:28 PM
why do more work when you don't have to?!

CyberAlien
01-26-2004, 05:18 AM
Originally posted by mg-
why do more work when you don't have to?!
yep, exactly. if you need to echo file use readfile(), if you need to get it in string use file_get_contents().

Rich2k
01-26-2004, 05:48 AM
Originally posted by mg-
fopen/fread seems to work for my nicely.. I had to make a bot that parsed alil over 100,000 pages. Took a day because it was remote... but it worked! :D

Well for me ever since PHP 4.3.2 (and I did find a reference to this in the PHP bugs database once) it stops reading remote files after a certain number of characters (regardless of what you put in the fread() statement)).

SEATi
01-26-2004, 08:39 PM
Rich2k,

You can avoid that using feof()

Rich2k
01-27-2004, 05:41 AM
Yeah but it's much better to use streams if possible so I switched away from using fopen() completely for remote files.