phpfpm

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2018 License: BSD-3-Clause, MIT Imports: 12 Imported by: 0

README

phpfpm GoDoc

phpfpm is a minimalistic php-fpm process manager written in go.

It generates config file for a simple php-fpm process with 1 pool and listen to 1 address only.

This is a fringe case, I know. Just hope it might be useful for someone else.

Usage

package main

import "github.com/yookoala/gofast/tools/phpfpm"

func main() {

  fpm := phpfpm.NewProcess("/usr/sbin/php5-fpm")

  // config to save pidfile, log to "/home/foobar/var"
  // also have the socket file "/home/foobar/var/php-fpm.sock"
  fpm.SetDatadir("/home/foobar/var")

  // save the config file to basepath + "/etc/php-fpm.conf"
  fpm.SaveConfig(basepath + "/etc/php-fpm.conf")
  fpm.Start()

  go func() {

    // do something that needs fpm
    // ...
    fpm.Stop()

  }()

  // will wait for phpfpm to exit
  fpm.Wait()

}

License

This software is license under MIT License. You may find a copy of the license in this repository.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindBinary

func FindBinary(dirPaths ...string) (fpmPath string, err error)

FindBinary finds php-fpm binary in the given paths.

Will return ErrNotExist or other syscall error if it have problem finding the file. Will return other errors when reading from bad input / directory system.

func ReadPaths

func ReadPaths(envPath string) (dirPaths []string)

ReadPaths reads a UNIX $PATH (or otherwise formatted alike variable) and expand into an array of paths.

Types

type Process

type Process struct {

	// basename for pid / sock / log filename
	Name string

	// path to php-fpm executable
	Exec string

	// path to the config file
	ConfigFile string

	// username of the FastCGI process
	User string

	// The address on which to accept FastCGI requests.
	// Valid syntaxes are: 'ip.add.re.ss:port', 'port',
	// '/path/to/unix/socket'. This option is mandatory for each pool.
	Listen string

	// path of the PID file
	PidFile string

	// path of the error log
	ErrorLog string
	// contains filtered or unexported fields
}

Process describes a minimalistic php-fpm config that runs only 1 pool

Example
package main

import (
	"time"

	"github.com/yookoala/gofast/tools/phpfpm"
)

var username, basepath, pathToPhpFpm string

func main() {

	process := phpfpm.NewProcess(pathToPhpFpm)

	// SetDatadir equals to running these 3 settings:
	// process.PidFile  = basepath + "/phpfpm.pid"
	// process.ErrorLog = basepath + "/phpfpm.error_log"
	// process.Listen   = basepath + "/phpfpm.sock"
	process.SetDatadir(basepath + "/var")
	process.User = username

	// save the config file to basepath + "/etc/php-fpm.conf"
	process.SaveConfig(basepath + "/etc/example.conf")
	process.Start()

	go func() {
		// do something that needs phpfpm
		// ...
		time.Sleep(time.Millisecond * 50)
		process.Stop()
	}()

	process.Wait()

}
Output:

func NewProcess

func NewProcess(phpFpm string) *Process

NewProcess creates a new process descriptor

func (*Process) Address

func (proc *Process) Address() (network, address string)

Address returns networkk and address that fits the use of either net.Dial or net.Listen

func (*Process) Config

func (proc *Process) Config() (f *ini.File)

Config generates an minimalistic config ini file in *ini.File format. You may then use SaveTo(path) to save it

func (*Process) SaveConfig

func (proc *Process) SaveConfig(path string)

SaveConfig generates config file according to the process attributes

func (*Process) SetDatadir

func (proc *Process) SetDatadir(prefix string)

SetDatadir sets default config values according with reference to the folder prefix

Equals to running these 3 statements:

process.PidFile  = prefix + "/" + proc.Name ".pid"
process.ErrorLog = prefix + "/" + proc.Name ".error_log"
process.Listen   = prefix + "/" + proc.Name ".sock"

func (*Process) SetName

func (proc *Process) SetName(name string)

SetName sets the base name for pid, error_log and sock file.

func (*Process) Start

func (proc *Process) Start() (err error)

Start starts the php-fpm process in foreground mode instead of daemonize

func (*Process) Stop

func (proc *Process) Stop() error

Stop stops the php-fpm process with SIGINT instead of killing

func (*Process) Wait

func (proc *Process) Wait() (err error)

Wait wait for the process to finish

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL