greyhound

package module
v0.0.0-...-1ab4612 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2014 License: MIT Imports: 16 Imported by: 0

README

greyhound

A PHP development server written in my own time outside of work because apparently I'm a masochist (also because I wanted to do something interesting with Go).

Installation/usage

First make sure you have Go set up and GOPATH defined, etc. Then:

go get -u github.com/holizz/greyhound/greyhound
cd /var/vhosts/mysite
# Serve current directory on port 3000 with a timeout of 5s (these are the defaults)
greyhound -d . -p 3000 -t 5s

It shows you the errors as if you were using Rails or Sinatra - i.e. it doesn't render the page and just shows you the error. Due to needing to listen on php's STDERR for errors, PhpHandler can only handle one request at a time. For performance the CLI tool will serve non-php files without using PhpHandler.

Sometimes you have to work with poor quality software, so there's an option to ignore errors (it takes the whole error string and checks if your argument to -i is in it):

# Ignore errors from some badly-written WordPress plugins (almost a tortology)
greyhound -i /wp-content/plugins/badplugin/ -i /wp-content/plugins/reallybadplugin/

Hacking

Documentation: http://godoc.org/github.com/holizz/greyhound

Issues: https://github.com/holizz/greyhound/issues

License

MIT (see LICENSE.txt)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FallbackHandler

type FallbackHandler struct {
	// contains filtered or unexported fields
}

If a request represents a file that doesn't end with fallbackSuffix, serve it with http.FileHandler, otherwise serve it with fallback.

func NewFallbackHandler

func NewFallbackHandler(dir string, fallbackSuffix string, fallback http.Handler) (fh *FallbackHandler)

func (*FallbackHandler) ServeHTTP

func (fh *FallbackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PhpHandler

type PhpHandler struct {
	// contains filtered or unexported fields
}

A PhpHandler represents a single PHP process running the built-in Web server.

Due to the need to check for errors in the STDERR of the process it only allows one call to ServeHTTP() at a time (using sync.Mutex).

func NewPhpHandler

func NewPhpHandler(dir string, timeout time.Duration, args, ignore []string) (ph *PhpHandler, err error)

NewPhpHandler starts a new PHP server listening on the first free port (between port 8001 and 2^16).

Usage:

ph, err := NewPhpHandler("/path/to/web/root", time.Second)
if err != nil {
        panic(err)
}
defer ph.Close()

timeout is in milliseconds

func (*PhpHandler) Close

func (ph *PhpHandler) Close()

Close must be called after a successful call to NewPhpHandler otherwise you may get stray PHP processes floating around.

func (*PhpHandler) ServeHTTP

func (ph *PhpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP sends an http.Request to the PHP process, writes what it gets to an http.ResponseWriter.

If an error gets printed to STDERR during the request, it shows the error instead of what PHP returned. If the request takes too long it shows a message saying that the request took too long (see timeout option on NewPhpHandler).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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