fsockopen 还有其他好的选择吗?

发布于 2024-09-26 06:38:45 字数 669 浏览 1 评论 0原文

我正在尝试使下面的代码与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 技术交流群。

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

发布评论

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

评论(1

笨死的猪 2024-10-03 06:38:45

假设您使用 http/https 作为协议,类似以下内容应该可以工作:

$client = curl_init();

$options = array(
  CURLOPT_PORT => $port
  CURLOPT_RENTURNTRANSFER => true,
  CURLOPT_SSL_VERIFYPEER => false, // dont verify the cert
  CURLOPT_URL => ($issecure ? 'https://' : 'http://'). $host
);

$response = curl_exec($client);

if(false !== $response) {
  echo $response;
  return $response;
} else {
  if($error = curl_error($client)) {
    echo $error;
    return $error;
  } else {
    echo 'Something is wrong. Error could not be determined.';
  }
}

另一个很棒且更容易使用的选项是 Zend_Http_Client,它支持 fsockopencurl 因此您可以轻松地来回切换,而无需修改代码。

Assuming youre using http/https as the protocol somethig like the following should work:

$client = curl_init();

$options = array(
  CURLOPT_PORT => $port
  CURLOPT_RENTURNTRANSFER => true,
  CURLOPT_SSL_VERIFYPEER => false, // dont verify the cert
  CURLOPT_URL => ($issecure ? 'https://' : 'http://'). $host
);

$response = curl_exec($client);

if(false !== $response) {
  echo $response;
  return $response;
} else {
  if($error = curl_error($client)) {
    echo $error;
    return $error;
  } else {
    echo 'Something is wrong. Error could not be determined.';
  }
}

Another great and much eaiser to use option would be Zend_Http_Client it supports fsockopen, and curl so you can switch back and forth quite easily without modifying code.

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