gophpfpm

package module
v0.0.0-...-b22dafd Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2017 License: MIT Imports: 11 Imported by: 0

README

gophpfpm Travis GoDoc

gophpfpm 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/gophpfpm"

func main() {

  phpfpm := gophpfpm.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"
  phpfpm.SetDatadir("/home/foobar/var")

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

  go func() {

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

  }()

  // will wait for phpfpm to exit
  phpfpm.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

This section is empty.

Types

type Process

type Process struct {

	// 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/gophpfpm"
)

var username, basepath, pathToPhpFpm string

func main() {

	process := gophpfpm.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  = basepath + "/phpfpm.pid"
process.ErrorLog = basepath + "/phpfpm.error_log"
process.Listen   = basepath + "/phpfpm.sock"

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