hhxsv5 / laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.
MIT License
3.84k stars 475 forks source link

Laravels显示启动成功,但没有开启进程,重启显示Swoole is not running #262

Closed ouyuan2016 closed 4 years ago

ouyuan2016 commented 4 years ago
  1. Your software version (Screenshot of your startup)

+--------------------------+---------+ | Component | Version | +--------------------------+---------+ | PHP | 7.4.5 | | Swoole | 4.4.12 | | LaravelS | 3.7.3 | | Laravel Framework [prod] | 6.18.18 | +--------------------------+---------+

  1. Detail description about this issue(error/log) 我的DOCKERFILE
    
    ARG ALPINE_VERSION=${ALPINE_VERSION:-"3.11"}
    FROM alpine:$ALPINE_VERSION
    ARG ALPINE_VERSION
    # trust this project public key to trust the packages.
    ADD https://dl.bintray.com/php-alpine/key/php-alpine.rsa.pub /etc/apk/keys/php-alpine.rsa.pub

ENV SWOOLE_VERSION=${SWOOLE_VERSION:-"4.5.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"

--build-arg timezone=Asia/Shanghai

ARG timezone

ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \ COMPOSER_VERSION=1.10.7 \ APP_ENV=prod

---------- building ----------

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ && set -ex \

change apk source repo

&& echo "https://dl.bintray.com/php-alpine/v${ALPINE_VERSION}/php-7.4" >> /etc/apk/repositories \
&& echo "@php https://dl.bintray.com/php-alpine/v${ALPINE_VERSION}/php-7.4" >> /etc/apk/repositories \
&& apk add --no-cache libstdc++ openssl git bash \
&& apk add --no-cache --virtual .build-deps $PHPIZE_DEPS libaio-dev openssl-dev \
&& apk update \
&& apk add --no-cache \
# Install base packages ('ca-certificates' will install 'nghttp2-libs')
ca-certificates \
curl \
wget \
tar \
xz \
libressl \
tzdata \
pcre \
php7 \
php7-bcmath \
php7-curl \
php7-ctype \
php7-dom \
php7-gd \
php7-iconv \
php7-json \
php7-mbstring \
php7-mysqlnd \
php7-openssl \
php7-pdo \
php7-pdo_mysql \
php7-pdo_sqlite \
php7-phar \
php7-posix \
php7-redis \
php7-sockets \
php7-sodium \
php7-sysvshm \
php7-sysvmsg \
php7-sysvsem \
php7-zip \
php7-zlib \
php7-xml \
php7-xmlreader \
php7-pcntl \
&& ln -sf /usr/bin/php7 /usr/bin/php \
# mongodb install
&& pecl install mongodb \
&& echo "extension=mongodb.so" > /etc/php7/conf.d/mongodb.ini \
# download SWOOLE
&& cd /tmp \
&& curl -SL "https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz" -o swoole.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-mysqlnd --enable-openssl --enable-http2 \
    && make -s -j$(nproc) && make install \
) \
&& echo "extension=swoole.so" > /etc/php7/conf.d/50_swoole.ini \
&& echo "swoole.use_shortname = 'Off'" >> /etc/php7/conf.d/50_swoole.ini \
# install composer
&& cd /tmp \
&& wget https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \
&& chmod u+x composer.phar \
&& mv composer.phar /usr/local/bin/composer \
&& composer config -g repo.packagist composer https://mirrors.aliyun.com/composer \
&& cd /etc/php7 \
    # - config PHP
&& { \
    echo "upload_max_filesize=100M"; \
    echo "post_max_size=108M"; \
    echo "memory_limit=1024M"; \
    echo "date.timezone=${TIMEZONE}"; \
   } | tee conf.d/99-overrides.ini \
# - config timezone
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo "${TIMEZONE}" > /etc/timezone \
# ---------- clear works ----------
&& apk del --purge *-dev \
&& apk del .build-deps \
&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man /usr/share/php7 /usr/local/bin/php* \
&& php -v \
&& php -m \
&& php --ri swoole \
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"

EXPOSE 9501



3. Some `reproducible` code blocks and `steps`

![image](https://user-images.githubusercontent.com/20590949/83966276-d30f5600-a8eb-11ea-8a60-714b0f9538d4.png)
ouyuan2016 commented 4 years ago

配置都是默认的,除了改了个端口其他没变

bash-5.0# php bin/laravels start
 _                               _  _____ 
| |                             | |/ ____|
| |     __ _ _ __ __ ___   _____| | (___  
| |    / _` | '__/ _` \ \ / / _ \ |\___ \ 
| |___| (_| | | | (_| |\ V /  __/ |____) |
|______\__,_|_|  \__,_| \_/ \___|_|_____/ 

Speed up your Laravel/Lumen
>>> Components
+--------------------------+---------+
| Component                | Version |
+--------------------------+---------+
| PHP                      | 7.4.5   |
| Swoole                   | 4.4.12  |
| LaravelS                 | 3.7.3   |
| Laravel Framework [prod] | 6.18.18 |
+--------------------------+---------+
>>> Protocols
+-----------+--------+-------------------+--------------+
| Protocol  | Status | Handler           | Listen At    |
+-----------+--------+-------------------+--------------+
| Main HTTP | On     | Laravel Framework | 0.0.0.0:9501 |
+-----------+--------+-------------------+--------------+

bash-5.0# php bin/laravels reload
[2020-06-07 18:04:57] [ERROR] It seems that Swoole is not running.

storage 目录下 只生成了 laravels.json的文件

hhxsv5 commented 4 years ago

1.检查storage目录是否可写; 2.startps -ef|grep laravels看看进程列表。

ouyuan2016 commented 4 years ago

1.检查storage目录是否可写; 2.startps -ef|grep laravels看看进程列表。

1.storage目录如果不可写为什么laravels.json可生成 就是没pid和另外一个

  1. 进程就是没有呀 因为我没用 -d 正常不加-d上是会进入进程的执行状态 除非ctrl+c停止 但目前就是类似启动后就停止的状态 补充一下: 1.我用的docker-composer搭建的环境 其中我使用privileged: true应该是没问题
    laravel:
    image: php7.4-cli
    restart: on-failure
    container_name: laravel
    privileged: true
    hostname: laravel
    tty: true
    links:
      - redis:redis_db
      - mysql:mysql_db
    volumes:
      - /www/laravel:/www
    ports:
      - "9501:9501"
    decpends_on:
      - redis
      - mysql

    2.挂载的目录里面的storage目录我是用给了777的 3.我用swoole官方的示例运行了一下(容器内)是可以正常开启进程的

    $http = new Swoole\Http\Server("127.0.0.1", 9501);
    $http->on('request', function ($request, $response) {
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
    });
    $http->start();
hhxsv5 commented 4 years ago

使用你的 Dockerfile 新建了 Laravel 6 工程,没有问题,能正常启动。 image image

你检查下Swoole和Laravel日志。

ouyuan2016 commented 4 years ago

检查下Swoole和Laravel日志 没有相关的错误报告 只有在composer install的时候发生错误 image 可能就是这个原因导致启动失败,但是项目是能正常运行的,找了很久也没能找到具体原因,网上说是代码错误,但是都显示加载成功了(Package manifest generated successfully.) 后来重新换了一个centos7环境安装(原来ubuntu16.x),扩展是能正常调起swoole的

hhxsv5 commented 4 years ago

看起来应该是环境问题,我们生产环境是基于这个Dockerfile,可参考下。