Skip to content

cboxdk/fcgx

Repository files navigation

fcgx

A minimal, robust, and modern FastCGI client library for Go.

fcgx is designed for integrating with PHP-FPM and other FastCGI servers, aiming for idiomatic Go, high testability, and correct protocol handling. It supports context, deadlines, timeouts, and structured error handling.

Built with ❤️ by cbox.dk - Experts in cloud infrastructure and modern web solutions.

Features

  • Idiomatic, thread-safe Go API
  • Context and timeout support on all requests
  • Structured sentinel errors for robust error handling (errors.Is)
  • Manual and reliable FastCGI protocol handling
  • Designed for integration with PHP-FPM status, pool metrics, and more
  • Well-suited for Kubernetes, Docker, and production monitoring

Quick Example

import (
    "context"
    "github.com/cboxdk/fcgx"
    "io"
    "time"
)

func main() {
    ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
    defer cancel()

    client, err := fcgx.DialContext(ctx, "unix", "/var/run/php-fpm.sock")
    if err != nil {
        panic(err)
    }
    defer client.Close()

    params := map[string]string{
        "SCRIPT_FILENAME": "/usr/share/phpmyadmin/index.php",
        "SCRIPT_NAME":     "/index.php",
        "REQUEST_METHOD":  "GET",
        "SERVER_PROTOCOL": "HTTP/1.1",
        "REMOTE_ADDR":     "127.0.0.1",
    }

    resp, err := client.Get(ctx, params)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    println(string(body))
}

Error Handling

fcgx returns strong sentinel errors for key error categories:

  • ErrClientClosed
  • ErrTimeout
  • ErrContextCancelled
  • ErrUnexpectedEOF
  • ErrInvalidResponse
  • ErrWrite, ErrRead

Use errors.Is to match error causes in your code.

About cbox.dk

This library is developed and maintained by cbox.dk, a Danish company specializing in:

  • Cloud infrastructure solutions
  • Modern web development
  • DevOps and container orchestration
  • High-performance backend systems

We build reliable, scalable solutions for businesses of all sizes. Visit us at cbox.dk to learn more about our services.

Authors

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •