PHP hyperf如何配置yasd调试环境

藏色散人
发布: 2023-03-12 06:54:02
转载
3148 人浏览过

前言

hyperf的环境采用docker构建

Docker

Dockerfile采用hyperf的镜像文件,额外添加了yasd的扩展。

# hyperf/hyperf:7.4
#
# @link     https://www.hyperf.io
# @document https://doc.hyperf.io
# @contact  group@hyperf.io
# @license  https://github.com/hyperf/hyperf/blob/master/LICENSE

ARG ALPINE_VERSION

FROM hyperf/hyperf:7.4-alpine-v${ALPINE_VERSION}-base

LABEL maintainer="Hyperf Developers <group@hyperf.io>" version="1.0" license="MIT"

ARG SW_VERSION
ARG COMPOSER_VERSION

##
# ---------- env settings ----------
##
ENV SW_VERSION=${SW_VERSION:-"v4.6.1"} \
    COMPOSER_VERSION=${COMPOSER_VERSION:-"2.0.2"} \
    #  install and remove building packages
    PHPIZE_DEPS="autoconf dpkg-dev dpkg file g++ gcc libc-dev make php7-dev php7-pear pkgconf re2c pcre-dev pcre2-dev zlib-dev libtool automake"

# update
RUN set -ex \
    && apk update \
    # for swoole extension libaio linux-headers
    && apk add --no-cache libstdc++ openssl git bash \
    && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS libaio-dev openssl-dev curl-dev \
    # download
    && cd /tmp \
    && curl -SL "https://github.com/swoole/swoole-src/archive/${SW_VERSION}.tar.gz" -o swoole.tar.gz \
    && curl -SL "https://gitee.com/ls-yw/yasd/repository/archive/v0.3.7?format=tar.gz" -o yasd.tar.gz \
    && ls -alh \
    # php extension:swoole
    && cd /tmp \
    && mkdir -p swoole \
    && tar -xf swoole.tar.gz -C swoole --strip-components=1 \
    && ln -s /usr/bin/phpize7 /usr/local/bin/phpize \
    && ln -s /usr/bin/php-config7 /usr/local/bin/php-config \
    && ( \
        cd swoole \
        && phpize \
        && ./configure --enable-openssl --enable-http2 --enable-swoole-curl --enable-swoole-json \
        && make -s -j$(nproc) && make install \
    ) \
    && echo "memory_limit=1G" > /etc/php7/conf.d/00_default.ini \
    && echo "opcache.enable_cli = &#39;On&#39;" >> /etc/php7/conf.d/00_opcache.ini \
    && echo "extension=swoole.so" > /etc/php7/conf.d/50_swoole.ini \
    && echo "swoole.use_shortname = &#39;Off&#39;" >> /etc/php7/conf.d/50_swoole.ini \
    # yasd debug
    && apk add --no-cache boost boost-dev \
    && cd /tmp \
    && mkdir -p yasd \
    && tar -xf yasd.tar.gz -C yasd --strip-components=1 \
    && ( \
        cd yasd \
        && phpize \
        && ./configure \
        && make && make install \
    ) \
    && echo "zend_extension=yasd.so" > /etc/php7/conf.d/50_yasd.ini \
    && echo "yasd.debug_mode=remote" >> /etc/php7/conf.d/50_yasd.ini \
    && echo "yasd.remote_host=172.16.13.27" >> /etc/php7/conf.d/50_yasd.ini \
    && echo "yasd.remote_port=9000" >> /etc/php7/conf.d/50_yasd.ini \
    # install composer
    && wget -nv -O /usr/local/bin/composer https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \
    && chmod u+x /usr/local/bin/composer \
    # php info
    && php -v \
    && php -m \
    && php --ri swoole \
    && composer \
    # ---------- clear works ----------
    && apk del .build-deps \
    && rm -rf /var/cache/apk/* /tmp/* /usr/share/man /usr/local/bin/php* \
    && echo -e "\033[42;37m Build Completed :).\033[0m\n"
登录后复制

构建镜像

docker build -t php7.4-alpine-v3.11-swoole:v4.6.1-ext –build-arg ALPINE_VERSION=3.11 –build-arg SW_VERSION=v4.6.1 .

启动容器

docker run –name demo -e PHP_IDE_CONFIG=”serverName=hyperf” -v E:\code\project:/data/project -p 58006:58006 -p 9000:9000 -itd –privileged -u root –entrypoint /bin/sh php7.4-alpine-v3.11-swoole:v4.6.1-ext

php -v检查yasd是否安装成功,出现Yasd相关则表示成功了

phpstorm

debug配置

Server的name注意和容器的PHP_IDE_CONFIG环境变量保持一致
点击小电话启动监听

结果

启动服务php -e bin/hyperf.php start

浏览器请求打上断点的接口,phpstorm输出调试窗口。

hyperf要注意在代理类中打断点

参考链接

  • https://huanghantao.github.io/yasd-wiki/#/%E5%89%8D%E8%A8%80/%E9%A1%B9%E7%9B%AE%E4%BB%8B%E7%BB%8D
  • https://github.com/swoole/docker-swoole/tree/master/examples/35-debug-with-yasd
  • github.com/hyperf/hyperf-docker
推荐:《PHP视频教程

以上是PHP hyperf如何配置yasd调试环境的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:learnku.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板