fopen() behind proxy server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nicolas777
Forum Newbie
Posts: 4
Joined: Tue Apr 15, 2003 8:45 am
Contact:

fopen() behind proxy server

Post by Nicolas777 »

Hi,

I have a problem with fopen() function.

I'm working on localhost and my computer is behind proxy server. I'm trying to open URL with fopen() function and the script tells me the following:

failed to create stream: Invalid argument in ...
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

You're trying to open a URL? Do you mean you're trying to open a file on another server?
Nicolas777
Forum Newbie
Posts: 4
Joined: Tue Apr 15, 2003 8:45 am
Contact:

Post by Nicolas777 »

Yes. I want to open jpg file from some server.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

url-wrappers are enabled?

Code: Select all

<?php phpinfo(); ?>
will tell you

Code: Select all

Directive               Local Value Master Value
allow_call_time_pass_reference     Off          Off
allow_url_fopen                    On           On
...
Nicolas777
Forum Newbie
Posts: 4
Joined: Tue Apr 15, 2003 8:45 am
Contact:

Post by Nicolas777 »

Code: Select all

Directive                     Local Value Master Value 
allow_call_time_pass_reference     On          On 
allow_url_fopen                    On          On
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

is it a transparent proxy used for all outgoing inet-connections?
try

Code: Select all

<html><body><pre>
<?php
	// 64.246.30.37 --> php.net
	echo "gethostbyaddr('64.246.30.37') : ";
	flush();
	echo gethostbyaddr('64.246.30.37'), "\n";
	
	echo "fsockopen with ip \n";
	flush();
	$s = fsockopen('64.246.30.37', 80, $errno, $errstr, 15) or die('fsockopen failed : #'. $errno . ', '. $errstr);
	fclose($s);
	
	echo "fopen with ip \n";
	flush();
	$fp = fopen('http://64.246.30.37', 'rb') or die('fopen/http-ip failed');
	fclose($fp);
	
	echo "fopen with php.net \n";
	flush();
	$fp = fopen('http://php.net', 'rb') or die('fopen/http failed');
	
	echo "file('http://www.php.net')\n";
	flush();
	file('http://www.php.net')  or die('file/http failed');
	
	echo 'done.';
?>
</pre></body></html>
Nicolas777
Forum Newbie
Posts: 4
Joined: Tue Apr 15, 2003 8:45 am
Contact:

Post by Nicolas777 »

I ran this script, and it gives me the following result :

Code: Select all

gethostbyaddr('64.246.30.37') : 64.246.30.37
fsockopen with ip 

Warning:  fsockopen() &#1111;function.fsockopen]: php_hostconnect: connect failed in c:\program files\apache group\apache\htdocs\test.php on line 10

Warning:  fsockopen() &#1111;function.fsockopen]: unable to connect to 64.246.30.37:80 in c:\program files\apache group\apache\htdocs\test.php on line 10

Fatal error:  Maximum execution time of 30 seconds exceeded in c:\program files\apache group\apache\htdocs\test.php on line 10
Post Reply