fputs():提供的参数不是有效的流资源
您好,我正在尝试向使用 fsockopen 而不是 cURL 的 PHP 类添加私有代理支持,但我有点迷失了!
我有以下代码,它为每个 fputs 行生成错误警告:
fputs(): 提供的参数不是有效的流资源
任何帮助将不胜感激。
$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");
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");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该检查 $ptr 是否为假,如果为假则中断。请务必使用严格比较 (===)。
如果删除@符号,您将看到错误消息。 @符号通常是错误代码的指示符。
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.
我遇到了同样的问题并通过执行以下操作来解决它。
删除@符号并将时间限制增加到30,它就可以了。 :)
I have faced same problem and fix it by doing bellow things.
Remove @ sign and increase time limit to 30 and it works. :)