【问题标题】:Error running script.php: Port 9000 is busy运行 script.php 时出错:端口 9000 正忙
【发布时间】:2013-10-01 06:15:09
【问题描述】:

我在phpstorm 中设置了php.iniDebug config。尝试在 phpstorm 事件日志中调试 php 脚本输出:

"Error running script.php: Port 9000 is busy"

php.ini 结束:

        [XDebug]
        zend_extension="/usr/lib/php5/20090626+lfs/xdebug.so"
        xdebug.remote_enable=1
        xdebug.remote_port="9000" (the default port is 9000)
        xdebug.profiler_enable=1
        xdebug.profiler_enable_trigger = 1
        xdebug.profiler_output_dir="/etc/php5/xdebug/profiler_output_dir"

pStorm 中的调试端口也设置为 9000。netstat -na 输出为:

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN 

如果我设置为其他端口怎么办。例如将其设置为10001 似乎可以完成这项工作。或者只是如何使它正常工作。我不确定我是否了解xDebug 的工作原理。就像在 phpstorm 中运行 Debug("script.php")(Shift+F9) 并在文件中设置断点一样?

有人有想法吗?

编辑:

来自: http://xdebug.org/docs/remote

xdebug.remote_port
Type: integer, Default value: 9000
The port to which Xdebug tries to connect on the remote host. Port 9000 is the default for both the client and the bundled debugclient. As many clients use this port number, it is best to leave this setting unchanged.

如果我将端口更改为 9000 以外的端口怎么办?也许超过 50k。

【问题讨论】:

  • "Port 9000 is busy" - 这意味着另一个应用程序(不是 PhpStorm .. 或完全不同的 PhpStorm 实例)已经在该端口上侦听。 IDE 在该端口上侦听(接收连接),xdebug 是连接到 IDE 而不是其他方式的那个。 xdebug 官方文档详细解释了 xdebug 如何与调试客户端 (IDE) 一起工作:xdebug.org/docs/remote

标签: php linux port xdebug phpstorm


【解决方案1】:

在端口 9000 上运行的进程可能是 PhpStorm 本身。

检查当前使用的端口,如 Jacob 提到的(在 Windows cmd 上:netstat -a -b):

如果 PhpStorm.exe 列在 :9000 下,您只需在设置 > 构建中更改 内置服务器 的端口,执行、部署 > Debugger 到例如63342(这是我队友安装 PhpStorm 时的默认设置)。

【讨论】:

  • 对于 OSX,您可以使用 -lsof -n -i4TCP:9000 | 找到绑定到端口 9000 的应用程序grep 听
【解决方案2】:

GNU/Linux 解决方案(因为 Windows 之外还有生命):

遵循@aqm的解决方案

首先使用端口 9000 查找进程。

netstat -tulpn | grep :9000

你会得到这样的输出:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      3993/programname

你需要 PID 来用这个命令杀死进程:

kill -9 3993

注意:可能你的进程没有显示他的 PID,可能是你运行的 PHP-FPM 使用默认端口 9000,在这种情况下你可以更改 PHP -FPM 端口或 PHP Xdebug 端口。


解决方案 1 - 更改 Xdebug 配置:

编辑/etc/php/php.ini

搜索 xdebug.remote_port=9000 并替换为您的新端口


解决方案 2 - 更改 PHP-FPM 端口:

编辑/etc/php/php-fpm.conf

使用 listen = 127.0.0.1:9000 搜索行并将 9000 替换为您的新端口

然后重新加载服务:

systemctl reload php-fpm

然后编辑您的 nginx 或 apache 配置以告知此新端口,在 /etc/httpd/httpd.conf/etc/nginx/nginx.conf 中搜索 127.0.0.1:9000 并将其替换为您的新端口

重新加载你的服务器:

systemctl reload nginx

systemctl reload httpd

希望对你有帮助:),

合十。

【讨论】:

    【解决方案3】:

    基本上其他一些进程正在使用 9000 而不是让它走,通常对我来说另一个 IDE 同时运行

    Windows 修复 ->

    1. 使用 9000 查找进程

    打开 cmd.exe

    netstat -o

    C:\Users\AMC75>netstat -o
    
    Active Connections
    
     Proto  Local Address          Foreign Address        State           PID
     TCP    10.6.176.132:27018     livlt0124661:55375     ESTABLISHED     11104
     TCP    10.6.176.132:49271     chilynfe01:5061        ESTABLISHED     10120
     TCP    10.6.176.132:49379     hhefs14:netbios-ssn    ESTABLISHED     4
     TCP    10.6.176.132:49383     chifs08:netbios-ssn    ESTABLISHED     4
     TCP    10.6.176.132:51034     157.55.56.143:40002    ESTABLISHED     11104
     TCP    10.6.176.132:51038     db3msgr6011007:https   ESTABLISHED     11104
     TCP    10.6.176.132:51049     wb-in-f125:5222        ESTABLISHED     10860
     TCP    10.6.176.132:51282     wpapp020:50124         ESTABLISHED     848
     TCP    10.6.176.132:53014     ec2-107-23-104-135:https  ESTABLISHED     10860
     TCP    10.6.176.132:53015     ec2-107-23-104-135:https  ESTABLISHED     10860
     TCP    10.6.176.132:54774     157.56.116.205:12350   ESTABLISHED     11104
     TCP    10.6.176.132:54822     a23-198-48-60:https    CLOSE_WAIT      7500
     TCP    10.6.176.132:55166     upmon070:3306          ESTABLISHED     2652
     TCP    10.6.176.132:55261     lhr08s03-in-f9:http    ESTABLISHED     10860
     TCP    10.6.176.132:55570     upmon070:3306          ESTABLISHED     10980
    ..... BLAH BLAH BLAH
    
    1. 终止进程

    taskkill /PID XXXX

    1. PROFIT ... ?,你现在应该可以运行调试器了

    【讨论】:

      【解决方案4】:

      无法通过 lsof 和 netstat 识别在 9000 端口上运行的进程的 pid。临时最简单的解决方案就是将phpstormphp.ini 中的端口更改为其他未实际使用的端口(例如10k)。

      【讨论】:

        【解决方案5】:

        给未来的自己注意:

        在我的情况下,这是由使用虚拟机端口转发(Virtual Box 上的 vagrant)引起的。我认为转发9000 是个好主意。

        解决方案:连接到 VM IP 10.166.53.1,这是标准的 Virtual Box

        我的/etc/php5/cgi/conf.d/xdebug.ini的内容

        ; xdebug configuration
        ; xdebug.remote_host = localhost
        zend_extension =  /usr/lib/php5/20121212/xdebug.so
        xdebug.remote_connect_back = 1
        xdebug.remote_enable = 1
        xdebug.remote_port = 9000
        xdebug.remote_handler = dbgp
        xdebug.remote_mode = req
        xdebug.idekey = "PHPSTORM"
        xdebug.remote_log = /var/log/xdebug.log
        

        【讨论】:

        • 这里有同样的问题。显然你不需要转发这个端口。删除端口 9000 的转发为我修复了它。现在我可以使用 Vagrant + XDebug + PhpStorm
        【解决方案6】:

        首先,即使有点离题,我认为它也有帮助。我为每个 docker-composer 项目使用不同的网络接口。这样我就可以毫无顾虑地在 /etc/hosts 中映射一个持久域名,在这个例子中是192.168.33.102 project.domain.local

        以下是 yaml 设置示例:

        nginx:
          build: docker-images/nginx
          links:
            - "php"
          ports:
            - "192.168.33.102:80:80"
        php:
          build: docker-images/php/7.0.1-fpm
          ports:
            - "192.168.33.102:10000:9000"
        

        php 容器在 9001 上侦听 php7.0-fpm,在 9000 上侦听 xdebug,并且不公开任何端口。

        PhpStorm 调试端口设置为默认 9000,服务器主机设置为 192.168.33.102(或 /etc/hosts 中的值,即 project.domain.local)。

        从 php 容器的端口可以看出,不同的映射端口设置为 10000,它可以是除 9000 之外的任何其他值,以消除 PhpStorm 的忙错误。

        另外,在 docker-compose 上绑定端口也很重要。如果没有映射端口,它就无法工作,并且它无法与 9000:9000 一起使用。

        希望对其他人有所帮助!

        PS:这里是 xdebug.ini:

        zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so
        xdebug.remote_enable=1
        xdebug.remote_port=9000
        xdebug.remote_connect_back=1
        xdebug.remote_handler=dbgp
        xdebug.remote_mode=req
        xdebug.remote_autostart=true
        

        【讨论】:

          【解决方案7】:

          对我有用:

          在 linux 上查看使用的端口

          sudo netstat -tulpn | grep :90 
          

          结果

          tcp        0      0 0.0.0.0:9000            0.0.0.0:*               OUÇA       22719/docker-proxy  
          tcp6       0      0 :::9000                 :::*                    OUÇA       22726/docker-proxy  
          tcp6       0      0 :::9003                 :::*                    OUÇA       5252/java
          

          然后我改变了

          在 dockerfile 上:

          && echo "xdebug.client_port=9001" >> /usr/local/etc/php/conf.d/xdebug.ini \
          

          在 phpstorm 设置上

          设置 > PHP > 调试:

          Xdebug 部分:调试端口 9001

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-06-17
            • 1970-01-01
            • 1970-01-01
            • 2018-11-11
            • 1970-01-01
            • 2017-04-01
            • 1970-01-01
            • 2011-01-10
            相关资源
            最近更新 更多