FastCGI Client
A PHP FastCGI client to send requests (a)synchronously to PHP-FPM, or any other FastCGI server, using the FastCGI Protocol.
This library is based on the work of Pierrick Charron's PHP-FastCGI-Client and was ported and modernized to latest PHP versions, extended with some features for handling multiple requests (in loops) and unit and integration tests as well.
How it works
PHP-FPM runs PHP scripts for requests it receives via FastCGI. Usually a web server sends these requests. With this library, your own PHP script does — compare both:
1/6A browser requests /index.php from the web server via HTTP.
- web server works
- web server waits (blocked)
- on the way over the socket
- the script runs in PHP-FPM
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
→ GET /index.php HTTP/1.1
What you can do with it
- Execute PHP scripts through PHP-FPM without a web server in between, e.g. from CLI workers or cron jobs.
- Send requests synchronously, or asynchronously and in parallel, and collect the responses in the order they were sent or as soon as they are ready.
- Connect via network sockets or unix domain sockets.
- React to responses and failures with callbacks, or stream the output of long-running scripts with pass-through callbacks.
- Send any request method with URL-encoded, multipart (file upload), JSON or plain text content.
The library has no dependencies besides PHP itself and is continuously tested against PHP-FPM 8.0 – 8.5 as well as FastCGI servers written in Go, Rust, C# and Java.
Versions
This is the documentation of version 4.x, which requires PHP >= 8.0.
Please have a look at the backwards incompatible changes (BC breaks) in the changelog, if you upgrade from a previous version.
| Version | PHP | Documentation | Changelog |
|---|---|---|---|
| 4.x | >= 8.0 | This documentation | CHANGELOG.md |
| 3.x | >= 7.1 | 3.x | 3.x |
| 2.x | >= 7.1 | 2.x | 2.x |
| 1.x | >= 7.0 | 1.x | 1.x |
Version 3.x still gets bug fixes, but no new features.
Read more about the journey to and changes in v2.6.0
in this blog post.
Background
You can find an experimental use-case in my related blog posts:
You can also find slides of my talks about this project on speakerdeck.com.