Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged

V3 #3

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,38 +0,0 @@
# the http server listening address (required)
# [host]:<port>
PHOO_LISTEN="0.0.0.0:8000"

# the document root (required)
# from where you would like to serve static files?
PHOO_DOCUMENT_ROOT="/var/www/html/public"

# the router (required)
# where is your main script (the default script)
# till now we don't support serving multiple php files, it is only one,
# this works with modern frameworks
PHOO_ROUTER="/var/www/html/public/index.php"

# whether to enable/disable logs (optional, default: true)
# logs here means the http server level logs
PHOO_LOGS=true

# where is the php-fpm binary? (optional, default: php-fpm)
PHOO_FPM_BIN="php-fpm8.1"

# the php-fpm workers count (optional, default: CPU cors count)
PHOO_WORKERS_COUNT=100

# the maximum number each worker should handle before restarting
# this prevent memory-leaks some how (required).
PHOO_WORKER_MAX_REQUESTS=100

# the maximum time the request should take before killing it and its worker
PHOO_REQUEST_TIMEOUT=15s

# additional ini settings (optional, default: "")
# example: "extension=x.so;some_key=some_value;another_key=another_value"
PHOO_PHP_INI=""

# the user and the group used to run PHP-FPM as, (optional, default: www-data)
PHOO_PHP_USER="www-data"
PHOO_PHP_GROUP="www-data"
63 changes: 63 additions & 0 deletions .github/workflows/releaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
env:
CGO_ENABLED: "0"
REGISTRY: ghcr.io
IMAGE_NAME: alash3al/phoo

on:
release:
types: [created]

jobs:
binary-releaser:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "https://dl.google.com/go/go1.21.0.linux-amd64.tar.gz"
project_path: "./cmd"
binary_name: "phoo"
ldflags: "-s -w"

docker-releaser:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Get Latest Tag
id: var_tag
run: echo "name=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Github Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
file: Dockerfile
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.var_tag.outputs.name }}
cache-from: type=gha
cache-to: type=gha,mode=max
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.*
!.env.example
.phoo
!.env.example
.idea
21 changes: 0 additions & 21 deletions Dockerfile

This file was deleted.

74 changes: 56 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,60 @@
PHOO
====
> PHP high-performance application server and `php-fpm` supervisor.
> modern php application server, it depends on the bullet-proof `php-fpm` but it controls how it is being run.

Why?
====
> PHP isn't built for async world, so adopting the community, ecosystem and the mindset
> to be async isn't an easy task,
> but also I want very simple command to run, and it handles everything without too many configurations files,
> today most of the apps are using environment variables and the well-known `.env` file, so why there isn't a tool
> that you can ask to just run and configure everything from a single `.env` file, I don't want to add a hassle for understanding
> how `PHP-FPM` is working or anything else, all what I need it `$ phoo serve`, that's all.

How?
====
> Basically, `phoo` is a simple static-file as well a fastcgi reverse-proxy, but mainly focuses on `PHP`, not only that,
> but also, you can consider `phoo` a supervisor that manages `PHP-FPM` and its configurations to match today's setup.
> `phoo` is loading all the files in the document root into memory to accelerate static files serving, so don't put any huge file there.
Examples
========
> Imagine you have a php application uses modern framework like laravel, symfony ... etc
> that app contains a public directory, and that public directory contains the main bootstrap file that
> serves the incoming requests named as `index.php`.
```shell
# this all what you need to serve a laravel application!
$ phoo serve -r ./public
⇨ http server started on [::]:8000
```

#### But how about changing the address it is listening on to 0.0.0.0:80?
```shell
# no problem
$ phoo serve -r ./public --http 0.0.0.0:80
⇨ http server started on [::]:80
```

#### Sometimes I want to add custom `php.ini` settings, is it easy?
```shell
# is this ok for you? ;)
$ phoo serve -r ./public -i display_errors=Off -i another_key=another_value
⇨ http server started on [::]:8000
```
#### I have a high traffic web-app and I want to increase the php workers
```shell
# just increase the workers count
$ phoo serve -r ./public --workers=20
⇨ http server started on [::]:8000
```

#### Hmmmm, but I want to monitor my app via prometheus metrics, I don't want to do it manually
```shell
# no need to do it yourself, this will enable prometheus metrics at the specified `/metrics` path
$ phoo serve -r ./public --metrics "/metrics"
⇨ http server started on [::]:8000
```

#### Wow!, seems `phoo` has a lot of simple flags/configs, is it documented anywhere?
> just run `phoo serve --help` and enjoy it :), you will find that you can also pass flags via `ENV` vars, and it will automatically read `.env` file in the current working directory.

Requirements
============
- `php-fpm`
- a shell access to run `phoo` :D

Installation
============
- Binary installations could be done via the [releases](https://github.com/alash3al/phoo/releases).
- Docker image is available at [`ghcr.io/alash3al/phoo`](https://github.com/alash3al/phoo/pkgs/container/phoo)
- you can easily `COPY --from=ghcr.io/alash3al/phoo:2.1.8 /usr/bin/phoo /usr/bin/phoo` to run it into your own custom image!

Usage?
======
> for now, use our official docker image [here](https://github.com/alash3al/phoo/pkgs/container/phoo)
TODOs
=====
- [ ] Add `.env.example` with comments to describe each var.
- [ ] Add future plans/thoughts.
33 changes: 15 additions & 18 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,30 @@ package main

import (
"github.com/alash3al/phoo/cmd/serve"
"github.com/alash3al/phoo/pkg/symbols"
"github.com/joho/godotenv"
"github.com/labstack/gommon/log"
"github.com/urfave/cli/v2"
"log"
"os"
)
import _ "github.com/joho/godotenv/autoload"

func main() {
app := cli.NewApp()
app.Name = symbols.AppName
app.Version = symbols.AppVersion
app.Before = func(ctxCli *cli.Context) error {
filename := ctxCli.String(symbols.FlagNameEnvFilename)
if len(filename) < 1 {
return nil
}
return godotenv.Load(filename)
app := &cli.App{
Name: "phoo",
Description: "php modern applications serve that utilizes the bullet-proof php-fpm under-the-hood",
Suggest: true,
Version: "v3.x",
EnableBashCompletion: true,
SliceFlagSeparator: ";",
}

app.Flags = append(app.Flags, &cli.StringFlag{
Name: symbols.FlagNameEnvFilename,
Usage: "if provided, the configuration values will be loaded from it",
app.Commands = append(app.Commands, &cli.Command{
Name: "serve",
Flags: serve.DefaultFlags("PHOO"),
Before: serve.Before(),
Action: serve.Action(),
})

app.Commands = append(app.Commands, serve.Command())

if err := app.Run(os.Args); err != nil {
log.Error(err.Error())
log.Fatal(err.Error())
}
}
55 changes: 0 additions & 55 deletions cmd/serve/config.go

This file was deleted.

Loading