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

3.4k views Asked by At

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

There are 2 answers

3
TimWolla On

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.

0
Huzoor Bux On

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

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