Luke Bream
Luke Bream

Reputation: 855

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

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");

Upvotes: 1

Views: 3520

Answers (2)

Huzoor Bux
Huzoor Bux

Reputation: 1038

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

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

Upvotes: 0

TimWolla
TimWolla

Reputation: 32701

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.

Upvotes: 1

Related Questions