pub struct FpmHandle { /* private fields */ }
Expand description
A handle for managing a PHP-FPM (FastCGI Process Manager) instance.
This struct provides functionality to start, manage, and interact with a PHP-FPM process for testing purposes. It maintains the FPM process lifecycle and provides methods to send FastCGI requests to the running FPM instance.
The FpmHandle is designed as a singleton - only one instance can exist at a time, and it’s automatically cleaned up when the program exits.
Implementations§
Source§impl FpmHandle
impl FpmHandle
Sourcepub fn setup(
lib_path: impl AsRef<Path>,
log_path: impl AsRef<Path>,
) -> &'static FpmHandle
pub fn setup( lib_path: impl AsRef<Path>, log_path: impl AsRef<Path>, ) -> &'static FpmHandle
Sets up and starts a PHP-FPM process for testing.
This method creates a singleton FpmHandle instance that manages a PHP-FPM process with the specified PHP extension loaded. The FPM process is configured to listen on port 9000 and uses a temporary configuration file.
§Arguments
lib_path
- Path to the PHP extension library file (.so) to be loaded
§Returns
A static reference to the FpmHandle instance
§Panics
Panics if:
- PHP-FPM binary cannot be found
- FPM process fails to start
- FpmHandle has already been initialized
Sourcepub async fn test_fpm_request(
&self,
method: &str,
root: impl AsRef<Path>,
request_uri: &str,
content_type: Option<String>,
body: Option<Vec<u8>>,
)
pub async fn test_fpm_request( &self, method: &str, root: impl AsRef<Path>, request_uri: &str, content_type: Option<String>, body: Option<Vec<u8>>, )
Sends a FastCGI request to the PHP-FPM process and validates the response.
This method executes a FastCGI request to the running PHP-FPM instance using the specified parameters. It establishes a TCP connection to the FPM process and sends the request with the provided HTTP method, script path, and optional content.
The method automatically constructs the necessary FastCGI parameters including script filename, server information, and remote address details. After receiving the response, it validates that no errors occurred during processing.
§Arguments
method
- HTTP method for the request (e.g., “GET”, “POST”, “PUT”)root
- Document root directory where PHP scripts are locatedrequest_uri
- The URI being requested (e.g., “/test.php?param=value”)content_type
- Optional Content-Type header for the requestbody
- Optional request body as bytes
§Panics
Panics if:
- FpmHandle has not been initialized via
setup()
first - Cannot connect to the FPM process on port
- The PHP script execution results in errors (stderr is not empty)