Page 1 of 1

fopen() fwrite() probs - Novell server with PHP 4.2.4-dev

Posted: Mon Apr 28, 2003 5:47 am
by Skittlewidth
I've just transferred my fully functional news harvesting script over from a linux server to the Novell server its supposed to run on and its now coming up with the following errors:

Code: Select all

Warning: php_hostconnect: connect failed in data1:/staff/harvester/reap.php on line 5

Warning: fopen("http://www.guardian.co.uk/syndication/service/0,11065,334-0-5,00.html?U1271588", "r+") - Bad file number in data1:/staff/harvester/reap.php on line 5
could not open file
What is a bad file number?
There is another script on the server that uses fopen() and fread() sucessfully to open and read the text files that this particular script is trying to write to. Theory one is that this is a classic permissions problem.
I've tried with various urls, all with the same result EXCEPT when the file resides on the same server. Could it be that being an intranet server this server might not have a route out onto the internet?? hmmm.....

I'll post the script anyway:

Code: Select all

//** NEWS HARVESTER **//
function newsharvest($url,$file){
$fp = fopen($url, "r+") or die ("could not open file");// open url in read and write mode
$contents = fread ($fp, "5000"); // reads page upto 5000 bytes - url filesizes cannot be determined by filesize()
echo $contents;
$dest = fopen($file, "r+"); // opens my destination file in read and write mode
fwrite($dest, $contents); //write news contents to my destination file 
ftruncate($dest,ftell($dest)); // trim off any of the previous file contents that the update hasn't overwritten.
$size = filesize($file); // For me to monitor file sizes incase I have to change max read to  >5000
echo $size;
fclose($fp); //close all the files we've worked with to free memory.
fclose($dest);
} 

$test = "http://www.guardian.co.uk/syndication/service/0,11065,334-0-5,00.html?U1271588";
$test_file = "test.txt";
newsharvest($test, $test_file);
Thanks in advance to anyone who can give any advice!

Posted: Mon Apr 28, 2003 7:47 am
by d1223m
have you set up your config properly allowing fopen to access url's?
there is a php.ini setting but i cant remeber the name

if your just reading the complete contents of a file then you can use file("http://myUrl.com"); but i seem to remeber that that needs the same config var.

there are ways around this if you cant do it, check php.net/fopen - it has some other methods in the user comments.

Posted: Mon Apr 28, 2003 7:58 am
by []InTeR[]
$fp = fopen($url, "r+") or die ("could not open file");// open url in read and write mode
Write to a url?
Try readonly.

The reason why...

Posted: Mon Apr 28, 2003 9:31 am
by Skittlewidth
Yes, PHP is configured to allow fopen(), as I said, I've got another script doing it sucessfully on the same server.
As for "r+", [InTeR] you are right it is probably unnecessary and I can't remember why I put it there - maybe because I wasn't initially sure if it would let me copy the contents otherwise back when I originally wrote it.

In anycase the problem has been that the intranet server doesn't have any outgoing connection to the web, just as I had begun to suspect. Funny how we take these things for granted...

Thanks for your suggestions anyway! 8)