1

Hi I'm trying to add private proxy support to a PHP class that is using fsockopen rather than cURL and I'm a bit lost with it!

I have the following code which is producing an error warning for each of the fputs lines:

fputs(): supplied argument is not a valid stream resource

Any help would be really appreciated.

$proxyServer = '173.208.43.223';
$proxyPort = '8800';
$login = 'myuser'; // login name
$passwd = 'mypassword'; // password


$ptr = @fsockopen($proxyServer, $proxyPort, $errno, $errstr, $this->STIMEOUT);
fputs($ptr,"Proxy-Authorization: Basic ".base64_encode("$login:$passwd") ."\r\n");          
$uri = $server.":".$port;
fputs($ptr, 'GET '.$uri.' HTTP/1.0'."\r\n");
Luke Bream
  • 855
  • 2
  • 10
  • 15

2 Answers2

1

You should check whether $ptr is false or not and break if it is false. Be sure to use a strict comparison (===).

And if you remove the @-sign you will see the error messages. An @-sign is normally an indicator for bad code.

TimWolla
  • 31,849
  • 8
  • 63
  • 96
0

I have faced same problem and fix it by doing bellow things.

Remove @ sign and increase time limit to 30 and it works. :)

Huzoor Bux
  • 1,026
  • 4
  • 20
  • 46