fopen() fwrite() probs - Novell server with PHP 4.2.4-dev
Posted: Mon Apr 28, 2003 5:47 am
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:
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:
Thanks in advance to anyone who can give any advice!
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 fileThere 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);