无法绑定地址[0]:PHP错误 [英] unable to bind address [0]: php error

查看:65
本文介绍了无法绑定地址[0]:PHP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法绑定地址[0]:通常只允许每个套接字地址(协议/网络地址/端口)使用一种.错误是由我的PHP服务器页面给出的.我尝试从cmd中查找不同的端口号,就像编写netstat -an一样.我也搜索谷歌,但没有解决方案.我正在使用wamp服务器并在本地工作.谢谢.

unable to bind address [0]: Only one usage of each socket address (protocol/network address/port) is normally permitted.... error is given by my php server page. I tried different port numbers as looking from cmd as writing netstat -an. Also I searched on google but no solution. I am using wamp server and working local . Thanks .

<?php
// don't timeout
//echo phpinfo();
set_time_limit (0);
// set some variables
$host = "127.0.0.1";
$port = 1234;
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
// start listening for connections
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
echo "Waiting for connections...\n";
// accept incoming connections
// spawn another socket to handle communication
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
echo "Received connection request\n";
// write a welcome message to the client
$welcome = "Roll up, roll up, to the greatest show on earth!\n? ";
socket_write($spawn, $welcome, strlen ($welcome)) or die("Could not send connect string\n");
// keep looping and looking for client input
do
{
  // read client input
  $input = socket_read($spawn, 1024, 1) or die("Could not read input\n");
  if (trim($input) != "")
  {
    echo "Received input: $input\n";
    // if client requests session end
    if (trim($input) == "END")
    {
      // close the child socket
      // break out of loop
      socket_close($spawn);
      break;
    }
    // otherwise...
    else
    {
      // reverse client input and send back
      $output = strrev($input) . "\n";
      socket_write($spawn, $output . "? ", strlen (($output)+2)) or die("Could not write output\n");
      echo "Sent output: " . trim($output) . "\n";
    }
  }
} while (true);
// close primary socket
socket_close($socket);
echo "Socket terminated\n";
?>

推荐答案

Erm ...正在网页上运行吗?如果是这样,则每次点击该页面都会导致脚本尝试绑定到端口1234,一次只能发生一次.其他所有的人都会死.

Erm...this is running on a web page? If so, each hit to the page will cause the script to try to bind to port 1234, which ain't gonna happen for any but one at a time. All the others will die.

如果不是,那么我有两个原因可以立即想到绑定失败的原因:另一个程序已经在使用该端口,或者防火墙正在阻止该端口.对于127.0.0.1,后者不应该是这种情况,但是我已经看到了奇怪的事情发生.

If it's not, then there are two reasons i can think of right off why binding would fail: either another program is already using the port, or the firewall is blocking it. The latter shouldn't be the case for 127.0.0.1, but i've seen stranger things happen.

这篇关于无法绑定地址[0]:PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆