【问题标题】:Why can't xdebug3 access profile data in tmp folder?为什么 xdebug3 无法访问 tmp 文件夹中的配置文件数据?
【发布时间】:2021-05-12 12:35:53
【问题描述】:

我有一个安装了 xdebug 的 php docker 容器。

FROM php:8.0-fpm
RUN  pecl install xdebug-3.0.2 > /dev/null && \
     docker-php-ext-enable xdebug > /dev/null

我挂载的 xdebug.ini (/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini) 文件如下所示:

zend_extension=xdebug

xdebug.mode=debug,profile
xdebug.client_port= 9000
xdebug.start_with_request=yes
xdebug.output_dir = /tmp/profile

虽然 xdebug 有效,但我在探查器文件中看到了这一点:

Xdebug: [Profiler] File '/tmp/profile/cachegrind.out.15' could not be opened.

在 Dockerfile 的末尾,我将用户设置为 www-data

USER www-data

这就是它无法访问文件夹的原因吗?

xdebug 需要什么才能打开文件?它在 tmp 文件夹中,所以我认为它应该能够在那里具有读写权限。

【问题讨论】:

    标签: php docker xdebug


    【解决方案1】:

    Xdebug 需要指示写入探查器文件的目录存在。如果不存在,则无法写入文件,您将收到该错误消息。

    Xdebug 的 diagnostics 将尝试找出它无法写入文件的原因,并将尽职尽责地在其日志文件中报告(如果 xdebug.log 设置为可写文件名),以及通过在脚本中运行 xdebug_info() 时显示的诊断日志。

    在您的情况下,您需要确保您的 Dockerfile 包括:

    RUN mkdir /tmp/profile; chmod 777 /tmp/profile
    

    或者,如果你使用docker-compose,也可以绑定目录,用:

        volumes:
          - type: "bind"
            source: "/tmp/profile"
            target: "/tmp/profile"
    

    这是我在 Xdebug.org 的 docker-compose.yaml file 中所做的。

    docker-compose 应该在您的本地系统上创建 /tmp/profile 目录,如果它在启动容器时还不存在。

    【讨论】:

      【解决方案2】:

      我添加了:

      RUN mkdir /tmp/profile; chmod 777 /tmp/profile
      

      到 Dockefile。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-29
        • 2020-11-20
        • 2012-05-20
        相关资源
        最近更新 更多