detect

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package detect recognises PHP runtimes (the CLI, PHP-FPM, CGI, the Apache module, LiteSpeed, FrankenPHP and embedded builds) by content, not by name, and reads the version each one was built as.

Every PHP runtime links main/SAPI.c, which compiles the header "X-Powered-By: PHP/" PHP_VERSION into one NUL-terminated string, and the Zend engine, which compiles "Zend Engine v" ZEND_VERSION ", Copyright (c) ..." into another. A file is reported only when it is an executable or shared library (ELF, Mach-O or PE) and holds both strings, so source code, documentation, test fixtures and fingerprint databases that quote the header are not mistaken for PHP.

Index

Constants

This section is empty.

Variables

View Source
var Marker = []byte("X-Powered-By: PHP/")

Marker is the header string every PHP runtime carries.

Functions

func Executable

func Executable(head []byte) bool

Executable reports whether data starts like an ELF, Mach-O or PE file. head may be just the first bytes of the file.

func SAPI

func SAPI(p string) string

SAPI names how the file at p runs PHP, from its name and location.

func WebSAPI

func WebSAPI(s string) bool

WebSAPI reports whether the SAPI serves web requests directly.

Types

type Binary

type Binary struct {
	Path string `json:"path"`
	// Version is the PHP_VERSION string compiled in, exactly as found.
	Version string `json:"version"`
	// Zend is the Zend engine version compiled in.
	Zend string `json:"zend_version"`
	// SAPI is how this file runs PHP: cli, fpm-fcgi, cgi-fcgi, apache2handler,
	// litespeed, frankenphp, embed, or unknown.
	SAPI string `json:"sapi"`
	Size int    `json:"size"`
	// Digests of the file, used to confirm it is the file a package installed.
	MD5    []byte `json:"-"`
	SHA1   []byte `json:"-"`
	SHA224 []byte `json:"-"`
	SHA256 []byte `json:"-"`
	SHA384 []byte `json:"-"`
	SHA512 []byte `json:"-"`
	// Problem is set when the file is a PHP runtime but its version cannot be
	// trusted (several different versions, or a Zend version that contradicts it).
	Problem string `json:"problem,omitempty"`
}

Binary is one PHP runtime file.

func Inspect

func Inspect(p string, data []byte) *Binary

Inspect returns the PHP runtime in data, or nil when data is not one.

Jump to

Keyboard shortcuts

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