├── .gitignore ├── LICENSE ├── README.md └── template └── php7-swoole ├── Dockerfile ├── function └── src │ └── Handler.php ├── index.php └── template.yml /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Alex Ellis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Try it out: 2 | 3 | ``` 4 | $ faas tempate pull https://github.com/alexellis/php7-swoole-template 5 | 6 | $ faas new --lang php7-swoole swoole-test 7 | 8 | $ faas up --skip-push swoole-test 9 | 10 | $ echo -n | faas invoke swoole-test 11 | ``` 12 | -------------------------------------------------------------------------------- /template/php7-swoole/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.2 2 | 3 | RUN pecl install swoole 4 | 5 | RUN curl -sSL https://github.com/openfaas-incubator/of-watchdog/releases/download/0.4.5/of-watchdog > /usr/bin/fwatchdog \ 6 | && chmod +x /usr/bin/fwatchdog 7 | 8 | WORKDIR /root/ 9 | 10 | RUN echo "extension=swoole.so" | tee -a /usr/local/etc/php/conf.d/swoole.ini 11 | COPY function function 12 | COPY index.php index.php 13 | 14 | ENV fprocess="php index.php" 15 | ENV mode="http" 16 | ENV upstream_url="http://127.0.0.1:9501" 17 | ENV buffer_http="true" 18 | 19 | CMD ["fwatchdog"] 20 | -------------------------------------------------------------------------------- /template/php7-swoole/function/src/Handler.php: -------------------------------------------------------------------------------- 1 | on("start", function ($server) { 8 | echo "Swoole http server is started at http://127.0.0.1:9501\n"; 9 | }); 10 | 11 | $http->on("request", function ($request, $response) { 12 | 13 | // var_dump($request->rawContent()); 14 | var_dump($request->header); 15 | var_dump($request->server); 16 | // echo $request->server['request_method']; 17 | 18 | // echo $request->server['request_uri']; 19 | // echo $request->server['path']; 20 | // echo $request->rawContent(); 21 | // echo $request->header['host']; 22 | 23 | $res = (new App\Handler())->handle(""); 24 | $response->header("Content-Type", "text/plain"); 25 | $response->status(200); 26 | $response->end($res); 27 | }); 28 | 29 | $http->start(); 30 | -------------------------------------------------------------------------------- /template/php7-swoole/template.yml: -------------------------------------------------------------------------------- 1 | language: php7-swoole 2 | --------------------------------------------------------------------------------