Struct FpmHandle

Source
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

Source

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
Source

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 located
  • request_uri - The URI being requested (e.g., “/test.php?param=value”)
  • content_type - Optional Content-Type header for the request
  • body - 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)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,