Skip to content

Commit

Permalink
V4.0.0 (#34)
Browse files Browse the repository at this point in the history
1.重构command模块,借助symfony console包,入口代码更加规范整洁
2.兼容swoole 4以上版本,强制要求关闭协程
  • Loading branch information
kcloze authored Aug 11, 2019
1 parent a897cb7 commit c9ddc35
Show file tree
Hide file tree
Showing 16 changed files with 470 additions and 305 deletions.
16 changes: 12 additions & 4 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?php

/*
* This file is part of Swoole-jobs
* (c) kcloze <[email protected]>
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

$header = <<<'EOF'
This file is part of PHP CS Fixer.
This file is part of Swoole-jobs
(c) kcloze <[email protected]>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
Expand All @@ -15,7 +23,7 @@ return PhpCsFixer\Config::create()
'combine_consecutive_unsets' => true,
// one should use PHPUnit methods to set up expected exception instead of annotations
'general_phpdoc_annotation_remove' => ['expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'],
//'header_comment' => ['header' => $header],
'header_comment' => ['header' => $header],
//'heredoc_to_nowdoc' => true,
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
'no_unreachable_default_argument_value' => true,
Expand All @@ -34,12 +42,12 @@ return PhpCsFixer\Config::create()
'no_empty_statement' => true,
'simplified_null_return' => true,
'no_extra_consecutive_blank_lines' => true,
'pre_increment' => false
'pre_increment' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
)
->setUsingCache(false)
;
;
148 changes: 106 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,112 @@
#FROM daocloud.io/library/ubuntu:latest
FROM daocloud.io/library/php:7.1.10-cli-jessie
FROM alpine:3.9

MAINTAINER Kcloze <[email protected]>
LABEL maintainer="Swoole Jobs <[email protected]>" version="1.0" license="MIT"

RUN sed -i "s/archive.ubuntu./mirrors.aliyun./g" /etc/apt/sources.list
RUN sed -i "s/deb.debian.org/mirrors.aliyun.com/g" /etc/apt/sources.list
RUN sed -i "s/security.debian.org/mirrors.aliyun.com\/debian-security/g" /etc/apt/sources.list
##
# ---------- building ----------
##
RUN set -ex \
# change apk source repo
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories \
&& 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-pecl-amqp \
php7-bcmath \
php7-curl \
php7-ctype \
php7-dom \
php7-fileinfo \
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-simplexml \
php7-sockets \
php7-sodium \
php7-sysvshm \
php7-sysvmsg \
php7-sysvsem \
php7-tokenizer \
php7-zip \
php7-zlib \
php7-xml \
php7-xmlreader \
php7-xmlwriter \
php7-pcntl \
&& apk del --purge *-dev \
&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man /usr/share/php7 \
&& php -v \
&& php -m

RUN apt-get update && apt-get install -y \
libpng-dev \
libpq-dev \
g++ \
libicu-dev \
libxml2-dev \
htop \
git \
vim \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
zlib1g-dev \
librabbitmq-dev

RUN docker-php-ext-configure intl \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install intl \
&& docker-php-ext-install zip \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install pdo_pgsql \
&& docker-php-ext-install soap \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install opcache \
&& docker-php-ext-install mysqli \
&& pecl install amqp \
&& docker-php-ext-enable amqp \
&& pecl install apcu \
&& docker-php-ext-enable apcu \
&& pecl install swoole \
&& docker-php-ext-enable swoole \
&& pecl install redis \
&& docker-php-ext-enable redis
ARG swoole

VOLUME ["/data"]
WORKDIR /data
##
# ---------- env settings ----------
##
ENV SWOOLE_VERSION=${swoole:-"4.4.3"} \
# 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 zlib-dev libtool automake"

CMD [ "/bin/bash"]
# 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 \
# download
&& 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 \
&& ( \
cd swoole \
&& phpize \
&& ./configure --enable-mysqlnd --enable-openssl \
&& make -s -j$(nproc) && make install \
) \
&& printf "extension=swoole.so\n\
swoole.use_shortname = 'Off'\n\
swoole.enable_coroutine = 'Off'\n\
" >/etc/php7/conf.d/swoole.ini \
# clear
&& php -v \
&& php -m \
&& php --ri swoole \
# ---------- clear works ----------
&& apk del .build-deps \
&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man

RUN printf "# composer php cli ini settings\n\
date.timezone=PRC\n\
memory_limit=-1\n\
" > /etc/php7/php.ini
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
ENV COMPOSER_VERSION 1.9.0

RUN curl -SL "https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar" -o composer.phar \
&& mv composer.phar /usr/bin/composer \
&& chmod u+x /usr/bin/composer \
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"
50 changes: 23 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ composer install
* Building a mirror based on the root directory Dockerfile
* docker build -t swoole-jobs .
* docker run -it -v ~/data/code/php:/data swoole-jobs /bin/bash
* After entering the docker container, enter the project directory:php swoole-jobs.php start
* After entering the docker container, enter the project directory:
* `php ./bin/swoole-jobs.php start`

## 5. How to running

Expand All @@ -78,7 +79,7 @@ composer install
1.edit config.php
2.start service
php ./swoole-jobs.php start >> log/system.log 2>&1
php ./bin/swoole-jobs.php start >> log/system.log 2>&1
3.push jobs
php ./tests/testJobsSerialzie.php
Expand All @@ -88,46 +89,38 @@ php ./swoole-jobs.php start http
5.stop api server
php ./swoole-jobs.php stop http
```
### 5.2 Start parameter description
```
NAME
php swoole-jobs - manage swoole-jobs
- manage swoole-jobs

SYNOPSIS
php swoole-jobs command [options]
Manage swoole-jobs daemons.
-php bin/swoole-jobs.php app [options]
-Manage swoole-jobs daemons.

WORKFLOWS

-help [command]
-Show this help, or workflow help for command.

-restart
-Stop, then start swoole-jobs master and workers.

help [command]
Show this help, or workflow help for command.
restart
Stop, then start swoole-jobs master and workers.
-start
-Start swoole-jobs master and workers.

start
Start swoole-jobs master and workers.
-stop
-Wait all running workers smooth exit, please check swoole-jobs status for a while.

start http
Start swoole http server for apis.
-exit
-Kill all running workers and master PIDs.

stop
Wait all running workers smooth exit, please check swoole-jobs status for a while.
-http start
-Start swoole http server for apis.
stop http
Stop swoole http server for api.
exit
Kill all running workers and master PIDs.
exit http
Stop swoole http server for api.
-http stop
-Stop swoole http server for api.

```
### 5.3 API parameter description
Expand Down Expand Up @@ -161,12 +154,15 @@ WORKFLOWS
2. sudo cp -f systemd/swoole-jobs.service /etc/systemd/system/
3. sudo systemctl --system daemon-reload
4. Service management

```
#start service
sudo systemctl start swoole-jobs.service
#reload service
sudo systemctl reload swoole-jobs.service
#stop service
sudo systemctl stop swoole-jobs.service
```

## 7.System screenshot
Expand Down
Loading

0 comments on commit c9ddc35

Please sign in to comment.