Fast-CGI

module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT

README

Fast CGI Compatibility Layer

For Go Programming Language

FastCGI Logotype

This repository stores documentation of CGI and FastCGI interfaces and programming tools which may be useful for building applications using the FastCGI interface in Go programming language, a.k.a. Golang.

These tools include a library written in Go language. This library provides objects, methods and functions to work with FastCGI interface in Go programming language.

The library implements methods for a FastCGI client, mostly.

Implementation of a FastCGI server can be found in a built-in standard library of Go language – net/http/fcgi package, https://pkg.go.dev/net/http/fcgi.

Structure

N.B. Due to some bugs in Go language, the structure of this repository is heavily modified to meet the requirements of the Google's Golang proxy server which often throws funny messages. The most funny of them are messages stating that a package was downloaded but not found. If you are, like me, used to a strict repository layout which separates source code into an src folder and other stuff – into other folders, this structure is forbidden by Google's Golang.

So, knowing all the above, the structure of this repository is as follows:

  • DOC folder contains the documentation.
  • Other folders contain various parts of the library for Go language.

Usage

Usage examples can be found in the 'example' folder.

The most simple usage example requires only a few lines of code and is as simple as the following code:

package main

import (
  "fmt"
  "os"

  "github.com/vault-thirteen/Fast-CGI/pkg/models/php"
)

func main() {
  var err error
  err = runSimplePhpScript(`D:\Scripts\script.php`)
  if err != nil {
    panic(err)
  }
}

func runSimplePhpScript(scriptFilePath string) (err error) {
  var stdOut, stdErr []byte
  stdOut, stdErr, err = pm.RunOnceSimplePhpScript("tcp", "127.0.0.1:9000", scriptFilePath)
  if err != nil {
    return err
  }

  if len(stdErr) > 0 {
    _, err = fmt.Fprintln(os.Stderr, string(stdErr))
    if err != nil {
      return err
    }
  }

  if len(stdOut) > 0 {
    _, err = fmt.Fprintln(os.Stdout, string(stdOut))
    if err != nil {
      return err
    }
  }

  return nil
}

For more complex tasks, the Client object and its methods can be used.

Why ?

Reason 1

FastCGI interface provides a cross-platform and cross-language interface for communication between totally different programming languages. For example, with the help of FastCGI it is possible to call a function of a PHP language from the code written in Go language, where Go is a compiled language and PHP is an interpreted language with no runtime "engine".

Reason 2

FastCGI interface is still actual for simple tasks and applications where client code is not a bottleneck, e.g. for applications using a lot of complicated SQL queries, such as bulletin boards and online forums.

Reason 3

There are a lot of programming languages which still support the FastCGI interface. And many of these languages are mature and are sufficient for their purposes.

Reason 4

This library makes it possible to bring a new life into old projects written in other programming languages that support the FastCGI interface. It is not necessary to re-write PHP projects in Go from scratch. This is why it is said in this repository, that this project is a compatibility layer.

Feedback

If you have any feedback, you are free to direct it to this GitHub repository:

  • Comments should be written to the Discussions section: here
  • Bug reports should be directed to the Issues section: here

Jump to

Keyboard shortcuts

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