fsockopen 还有其他好的选择吗?
我正在尝试使下面的代码与curl 或其他东西一起使用。我已经查看了curl fsockopen 转换,但它不起作用。除了在我的主机上禁用 fsockopen 之外,代码可以正常工作。任何帮助将不胜感激。
$host = substr($hostport,0,50);
$port = substr($hostport,50,10);
$issecure = substr($hostport,60,1);
if($issecure=="Y")
{
$host = "ssl://".$host;
}
$fsok = fsockopen(trim($host) , intval(trim($port)));
if(FALSE == $fsok )
{
echo "Target Host not Found/Down"; return ;
}
fwrite($fsok, $bodyData );
$port ='';$host ='';$hostport= '';$bodyData='';
while ($line = fread($fsok, 25000))
{
echo $line;
}
fclose($fsok);
return $line;
I'm trying to make the code below work with curl or something. I have already taken a look at the curl fsockopen conversion but it doesn't work. The code works except that fsockopen is disabled on my host. Any help will be appreciated.
$host = substr($hostport,0,50);
$port = substr($hostport,50,10);
$issecure = substr($hostport,60,1);
if($issecure=="Y")
{
$host = "ssl://".$host;
}
$fsok = fsockopen(trim($host) , intval(trim($port)));
if(FALSE == $fsok )
{
echo "Target Host not Found/Down"; return ;
}
fwrite($fsok, $bodyData );
$port ='';$host ='';$hostport= '';$bodyData='';
while ($line = fread($fsok, 25000))
{
echo $line;
}
fclose($fsok);
return $line;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用 http/https 作为协议,类似以下内容应该可以工作:
另一个很棒且更容易使用的选项是
Zend_Http_Client
,它支持fsockopen
和curl
因此您可以轻松地来回切换,而无需修改代码。Assuming youre using http/https as the protocol somethig like the following should work:
Another great and much eaiser to use option would be
Zend_Http_Client
it supportsfsockopen
, andcurl
so you can switch back and forth quite easily without modifying code.