fputs():提供的参数不是有效的流资源

发布于 2024-12-27 00:59:55 字数 545 浏览 3 评论 0原文

您好,我正在尝试向使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开雨落又逢春i 2025-01-03 00:59:55

您应该检查 $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.

一花一树开 2025-01-03 00:59:55

我遇到了同样的问题并通过执行以下操作来解决它。

删除@符号并将时间限制增加到30,它就可以了。 :)

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文