Page 1 of 1

Copying file... failed to open stream

Posted: Mon Jul 21, 2003 6:39 am
by cggreer
G'day everyone!

My current project involves grabbing news headlines from a local news website and slotting them into the client's website. There's no copyright issues involved - all that has been cleared up (thank goodness :? )

Here's the problem:

Code: Select all

<?php
$GrabURL = urlencode("http://www.news.com.au/common/storylib/0,4810,BreakingNews%255EBREAKING%2520NEWS%255ETEXT%255Enews,00.html");
// 1. Grab the HTML
$RetrieveFile = implode ('', file ($GrabURL));
?>
When this code executes it generates the following errors:

Code: Select all

Warning: file(http%3A%2F%2Fwww.news.com.au%2Fcommon%2Fstorylib%2F0%2C4810%2CBreakingNews%25255EBREAKING%252520NEWS%25255ETEXT%25255Enews%2C00.html): failed to open stream: No such file or directory in D:\Program Files\Apache Group\Apache2\htdocs\MyHSCAdmin\TMPsb0s1idfog.php on line 94

Warning: implode(): Bad arguments. in D:\Program Files\Apache Group\Apache2\htdocs\MyHSCAdmin\TMPsb0s1idfog.php on line 94
When I replace the nasty looking $GrabURL with a local copy of the same file everything works no worries. The fopen_wrappers are turned on. I get the same errors running on two different servers!
Any help is v.v.appreciated!

Cheers,
Clinton Greer
cggreer@it.uts.edu.au

Posted: Mon Jul 21, 2003 6:43 am
by choppsta
At a glance it looks like you're urlencoding something that is already URL encoded...

Posted: Mon Jul 21, 2003 8:16 pm
by cggreer
Even without the urlencode() I still get the same errors on both servers.
I thought it might have been a problem with all the comments and arguments in the URL, however I get the same errors trying to load a plain .html page from another server.

I know both files exist because I can view them in the browser. Is there some setting in PHP.ini or in httpd.conf that needs to be changed to make this work?

Even trying to do a simple include("http://...") fails with similar errors.

eeek! Please help! :s

Clinton Greer
cggreer@it.uts.edu.au

...

Posted: Mon Jul 21, 2003 8:27 pm
by kettle_drum
If your getting errors that way, then why not try a different way of doing it. PHP has several ways to do every task - so just take a different route. Maybe something like:

Code: Select all

<?php

$file = "http://blah.com";
$fp = fopen($file, r);
while (!feof($fp)) {
   $data = fgets($fp, 1024);
   #do what you want with the data
}
?>

Posted: Wed Jul 23, 2003 9:35 am
by cggreer
Thanks, but I tried that too. It seems that any kind of function that involves resolving a remote address ie. "http://..." causes it to come up with this error.

Like I said, I thought it might have been the complex URL I was trying to grab, but it doesn't work using simple http://server.com/page1.html either.

As the page I intend to copy from is updated hourly, manually copying the file to the local system to reference isn't an option.

Any thoughts?

Ciao!
Clinton Greer
cggreer@it.uts.edu.au

Posted: Wed Jul 23, 2003 9:46 am
by patrikG
Have you had a look at the snoopy-class?
I find it quite useful in cases like yours.

Posted: Wed Jul 23, 2003 11:01 am
by cggreer
Snoopy looks promising, with lots of functionality. I'll try it out tomorrow morning and let you know! Fingers-crossed!!

Thanks mate!
Clinton Greer
cggreer@it.uts.edu.au

Posted: Mon Jul 28, 2003 7:13 am
by cggreer
ARGH! Snoopy does not work either - I end up with the same errors!

Here's the code I'm running (Snoopy sample):

Code: Select all

<?php
	include "Snoopy.class.inc";
	$snoopy = new Snoopy;
	
	$snoopy->user = "joe";
	$snoopy->pass = "bloe";
	
	if($snoopy->fetch("http://www.slashdot.org/"))
	{
		echo "response code: ".$snoopy->response_code."<br>\n";
		while(list($key,$val) = each($snoopy->headers))
			echo $key.": ".$val."<br>\n";
		echo "<p>\n";
		
		echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
	}
	else
		echo "error fetching document: ".$snoopy->error."\n";?>
Here's the errors I get (Apache 2.0.45 and PHP 4.2.3):

Code: Select all

Warning: fsockopen(): php_network_getaddresses: gethostbyname failed in D:\Program Files\Apache Group\Apache2\htdocs\MyHSCAdmin\Snoopy.class.inc on line 1061

Warning: fsockopen(): unable to connect to www.slashdot.org:80 in D:\Program Files\Apache Group\Apache2\htdocs\MyHSCAdmin\Snoopy.class.inc on line 1061
error fetching document: connection failed (0)
Anyone suggest anything?? PLEASE??!

Thanks,
Clinton Greer
cggreer@it.uts.edu.au