Documentation ¶
Index ¶
- func FindBinary(dirPaths ...string) (fpmPath string, err error)
- func ReadPaths(envPath string) (dirPaths []string)
- type Process
- func (proc *Process) Address() (network, address string)
- func (proc *Process) Config() (f *ini.File, err error)
- func (proc *Process) SaveConfig(path string) (err error)
- func (proc *Process) SetDatadir(prefix string)
- func (proc *Process) SetName(name string)
- func (proc *Process) SetWorker(worker int)
- func (proc *Process) Start() (err error)
- func (proc *Process) Stop() error
- func (proc *Process) Wait() (err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindBinary ¶
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.
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 // number of concurrent worker Worker int // 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 ( "os" "path" "time" "github.com/cyber-claws/gofast/tools/phpfpm" ) var username, basepath, pathToPhpFpm string func init() { var err error basepath, err = os.Getwd() if err != nil { panic(err) } basepath = path.Join(basepath, "_test") if pathToPhpFpm = os.Getenv("TEST_PHPFPM_PATH"); pathToPhpFpm != "" { } else if pathToPhpFpm, err = phpfpm.FindBinary(phpfpm.ReadPaths(os.Getenv("PATH"))...); err != nil { panic(err) } username = os.Getenv("USER") } 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" if err := process.SaveConfig(basepath + "/etc/example.conf"); err != nil { panic(err) } if err := process.Start(); err != nil { panic(err) } go func() { // do something that needs phpfpm // ... time.Sleep(time.Millisecond * 50) _ = process.Stop() }() if err := process.Wait(); err != nil { panic(err) } }
Output:
func NewProcess ¶
NewProcess creates a new process descriptor
func (*Process) Address ¶
Address returns networkk and address that fits the use of either net.Dial or net.Listen
func (*Process) Config ¶
Config generates an minimalistic config ini file in *ini.File format. You may then use SaveTo(path) to save it
func (*Process) SaveConfig ¶
SaveConfig generates config file according to the process attributes
func (*Process) SetDatadir ¶
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"