Download the PHP package mrizwan/laravel-fcgi-client without Composer
On this page you can find all versions of the php package mrizwan/laravel-fcgi-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mrizwan/laravel-fcgi-client
More information about mrizwan/laravel-fcgi-client
Files in mrizwan/laravel-fcgi-client
Package laravel-fcgi-client
Short Description A Laravel package for communicating with FastCGI-compatible servers (like PHP-FPM)
License MIT
Homepage https://github.com/muhammad-rizwan/laravel-fcgi-client
Informations about the package laravel-fcgi-client
Laravel FastCGI Client
A modern, Laravel-style FastCGI client that lets your Laravel application communicate directly with FastCGI-compatible servers like PHP-FPM.
The package works similarly to Laravel's HTTP Facade
Acknowledgements
This package is built as a fork of the fast-cgi-client library originally authored by hollodotme. We've adapted and extended it to provide seamless integration with Laravelβmany thanks to the original author for creating such a solid foundation.
What is FastCGI?
FastCGI is a protocol that allows a web server (like Nginx or Apache) to communicate with external applications, typically programming language interpreters like PHP-FPM (PHP FastCGI Process Manager). It's an improvement over the older CGI protocol, offering better performance through persistent processes.
In a traditional PHP web application setup, the web server (e.g., Nginx) receives HTTP requests and forwards them to PHP-FPM via FastCGI, which then executes the PHP scripts and returns the results.
Where This Package Can Be Used
This package enables Laravel applications to directly communicate with PHP-FPM, which opens up several use cases:
-
Microservices Architecture: Directly communicate with other PHP-based microservices without going through HTTP, reducing overhead.
-
Private API Access: Access internal APIs on remote servers via FastCGI instead of exposing them through HTTP endpoints.
-
Cross-Application Communication: Call scripts on another PHP application from your Laravel app with lower latency than HTTP requests.
- Gateway/Proxy Services: Create gateway services that can route requests to appropriate backend PHP services.
π Installation
π§ Configuration
The package automatically registers the service provider and facade in Laravel 9.x and above.
You can use the facade in your code by importing it:
β Basic Usage
- The URL must NOT include the protocol.
- E.g.:
example-domain.com/example-endpoint
- E.g.:
Simple GET Request
POST Request with Data
JSON Request
Defaults:
- Script path:
/var/www/public/index.php - Port: 9000
π‘ Available Methods
HTTP Methods
All HTTP methods support Laravel-like signatures with optional data arrays:
get(string $url, array $query = [])post(string $url, array $data = [])put(string $url, array $data = [])patch(string $url, array $data = [])delete(string $url, array $data = [])
Request Configuration
Content Type Configuration
Authentication
Method Chaining
You can chain multiple methods together for cleaner code:
π URL Templates
The package supports URL templates with parameter substitution:
π Response API
The response object provides a rich API similar to Laravel's HTTP client:
π Concurrent Requests with Laravel's Concurrency Facade
For Laravel 11+, you can use Laravel's built-in Concurrency facade to execute multiple FastCGI requests in parallel:
Moore Examples
Accessing a Remote API with URL Templates
Submitting a Form to a Remote Application
Creating a Resource on a Remote Service
RESTful API with URL Templates
Fetching Data from Multiple Services
Smart Content Type Defaults
The package intelligently chooses content types based on the HTTP method:
Error Handling
The package provides several ways to handle errors:
Retry Logic
For unstable services or network connections, you can add retry logic with intelligent defaults:
π§ͺ Testing
Tests are written using Pest PHP. Run them with:
π License
The MIT License (MIT). Please see License File for more information.