swoole / yasd

Yet Another Swoole Debugger
https://huanghantao.github.io/yasd-wiki/
Apache License 2.0
357 stars 35 forks source link

PHP 8, Docker and VS Code #94

Closed intellent closed 3 years ago

intellent commented 3 years ago

I am trying to get yasd running on PHP 8 inside Docker with VS Code in my Docker host.

My Dockerfile:

FROM php:8-cli

# Install yasd (XDebug alternative) and Swoole and use the default development configuration
RUN apt-get update && apt-get install -y dumb-init libboost-all-dev \
    && pecl install swoole \
    && docker-php-ext-enable swoole \
    && cd /tmp \
    && curl -L https://github.com/swoole/yasd/archive/v0.3.7.tar.gz --output yasd.tar.gz \
    && mkdir yasd && tar xzf yasd.tar.gz -C yasd --strip-components 1 \
    && cd yasd \
    && phpize --clean \
    && phpize \
    && ./configure \
    && make clean \
    && make \
    && make install \
    && cd / && rm -rf /tmp/* \
    && mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

# Add additional php.ini confs
COPY ./res/service-config/php/conf.d/*.ini /usr/local/etc/php/conf.d/

ENTRYPOINT ["/usr/bin/dumb-init", "--", "php", "-e"]

My yasd.ini:

zend_extension=yasd
yasd.debug_mode=remote
yasd.remote_host=host.docker.internal
yasd.remote_port=9000

My launch.json for VS Code:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/opt/my-app": "${workspaceRoot}"
            },
        }
    ]
}

When running my container, I instantly get the error:

Invalid address/ Address not supported: Function not implemented

If I remove the -e argument from the PHP call, my service starts and works fine. However, debugging from VS Code does not work (breakpoints not detected).

Any hints what else I can try?

huanghantao commented 3 years ago

You should use IP instead of host.docker.internal.

intellent commented 3 years ago

You should use IP instead of host.docker.internal.

Oh, okay. Afaik the internal IP of the Docker host is not static.

huanghantao commented 3 years ago

Thanks for your feedback, I will support the domain name in the next version.

huanghantao commented 3 years ago

Hi, we can use debug init file to set the remote_host. #98 #97

volodymyr-hordiienko commented 2 years ago

@huanghantao @intellent which ip should I use inside a docker? host.docker.internal, 127.0.0.1, 0.0.0.0 not working for me

host.docker.internal shows me error - [yasd] recv command error, connection closed but 127.0.0.1, 0.0.0.0 - [yasd] Connect IDE failed (Connection refused), please check that the IDE is in a listening state

could you help me please?

FROM hyperf/hyperf:8.0-alpine-v3.15-swoole

RUN set -ex \
    && apk add $PHPIZE_DEPS \
        openssl-dev \
        boost-dev \
    && ln -sf /usr/bin/phpize8 /usr/local/bin/phpize \
    && ln -sf /usr/bin/php-config8 /usr/local/bin/php-config

RUN git clone https://github.com/swoole/yasd.git \
    && cd yasd \
    && phpize --clean \
    && phpize \
    && ./configure \
    && make clean \
    && make \
    && make install

RUN echo "extension=yasd.so" > /etc/php8/conf.d/50_yasd.ini \
    && echo "yasd.debug_mode=remote" >> /etc/php8/conf.d/50_yasd.ini \
    && echo "yasd.remote_host=host.docker.internal" >> /etc/php8/conf.d/50_yasd.ini \
    && echo "yasd.remote_port=9000" >> /etc/php8/conf.d/50_yasd.ini

WORKDIR /data/project

COPY entrypoint.sh /scripts/entrypoint.sh
RUN chmod +x /scripts/entrypoint.sh

ENTRYPOINT ["/scripts/entrypoint.sh"]

Hyperf 2.2 scan_cacheable=true