All Projects → lisachenko → Protocol Fcgi

lisachenko / Protocol Fcgi

Licence: mit
FastCGI (FCGI) Protocol implementation for PHP

Projects that are alternatives of or similar to Protocol Fcgi

Nginx Helper
Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
Stars: ✭ 170 (+60.38%)
Mutual labels:  nginx, fastcgi
Dockerfiles
Collection of my Dockerfiles for many open-source projects
Stars: ✭ 104 (-1.89%)
Mutual labels:  nginx
Kcp
⚡ KCP - A Fast and Reliable ARQ Protocol
Stars: ✭ 10,473 (+9780.19%)
Mutual labels:  protocol
Production Ready Expressjs Server
Express.js server that implements production-ready error handling and logging following latest best practices.
Stars: ✭ 101 (-4.72%)
Mutual labels:  nginx
Mud
Multipath UDP library
Stars: ✭ 100 (-5.66%)
Mutual labels:  protocol
Php Fpm Queue
Use php-fpm as a simple built-in async queue
Stars: ✭ 103 (-2.83%)
Mutual labels:  fastcgi
Craftcms Docker
Craft3/Craft2 CMS Docker base (Nginx, PHP-FPM 8, PostgreSQL/MariaDB, Redis)
Stars: ✭ 99 (-6.6%)
Mutual labels:  nginx
Rtapi
Real time API latency analyzer - Create a PDF report and HDR histogram of your APIs
Stars: ✭ 106 (+0%)
Mutual labels:  nginx
Advanced Nginx
nginx的基础操作与总结、HTTP缓存、OpenSSL
Stars: ✭ 104 (-1.89%)
Mutual labels:  nginx
Nginx Vod Module
NGINX-based MP4 Repackager
Stars: ✭ 1,378 (+1200%)
Mutual labels:  nginx
One Sys
聚合koa2+pm2+vue-cli+element+axios的前后端一体开发脚手架
Stars: ✭ 102 (-3.77%)
Mutual labels:  nginx
Among Us Protocol
A writeup of the network protocol used in Among Us, a game by Innersloth.
Stars: ✭ 99 (-6.6%)
Mutual labels:  protocol
Docker Gunicorn Nginx
An experimental docker setup for Python / Gunicorn / Nginx stack
Stars: ✭ 103 (-2.83%)
Mutual labels:  nginx
Country Ip Blocks
CIDR country-level IP data, straight from the Regional Internet Registries, updated hourly.
Stars: ✭ 100 (-5.66%)
Mutual labels:  nginx
Redis Tools
my tools working with redis
Stars: ✭ 104 (-1.89%)
Mutual labels:  protocol
Nginx Haskell Module
Nginx module for binding Haskell code in configuration files for great good!
Stars: ✭ 99 (-6.6%)
Mutual labels:  nginx
Pycomm3
A Python Ethernet/IP library for communicating with Allen-Bradley PLCs.
Stars: ✭ 102 (-3.77%)
Mutual labels:  protocol
Docker Laravel
🐳 Docker Images for Laravel development
Stars: ✭ 101 (-4.72%)
Mutual labels:  nginx
Nginx Php Fpm
Nginx and php-fpm for dockerhub builds
Stars: ✭ 1,419 (+1238.68%)
Mutual labels:  nginx
Reverse Engineering Bluetooth Protocols
Intercepting Bluetooth device communication and simulating packet responses of an iPhone from a Raspberry Pi 3
Stars: ✭ 105 (-0.94%)
Mutual labels:  protocol

Object-oriented implementation of FCGI Protocol for PHP

FastCGI is an open extension to CGI that provides high performance for all Internet applications without the penalties of Web server APIs.

Many modern web-servers such as nginx, apache, lighthttpd, etc are communicating with PHP via FCGI. So, this protocol is well known and used in many applications. More detailed information about the protocol is available here here: http://www.fastcgi.com/devkit/doc/fcgi-spec.html

Build Status Scrutinizer Code Quality Code Coverage Packagist Minimum PHP Version License

Usage

This library can be used for implementing both client and server side of FCGI application. For example, nginx can connect to the PHP FCGI daemon, or some library code can connect to the FPM as a FCGI client.

To install this library, just write

$ composer require lisachenko/protocol-fcgi

After that you can use an API to parse/create FCGI requests and responses.

Simple FCGI-client:

<?php

use Lisachenko\Protocol\FCGI;
use Lisachenko\Protocol\FCGI\FrameParser;
use Lisachenko\Protocol\FCGI\Record;
use Lisachenko\Protocol\FCGI\Record\BeginRequest;
use Lisachenko\Protocol\FCGI\Record\Params;
use Lisachenko\Protocol\FCGI\Record\Stdin;

include "vendor/autoload.php";

// Let's connect to the local php-fpm daemon directly
$phpSocket = fsockopen('127.0.0.1', 9001, $errorNumber, $errorString);
$packet    = '';

// Prepare our sequence for querying PHP file
$packet .= new BeginRequest(FCGI::RESPONDER);;
$packet .= new Params(['SCRIPT_FILENAME' => '/var/www/some_file.php']);
$packet .= new Params();
$packet .= new Stdin();

fwrite($phpSocket, $packet);

$response = '';
while ($partialData = fread($phpSocket, 4096)) {
    $response .= $partialData;
    while (FrameParser::hasFrame($response)) {
        $record = FrameParser::parseFrame($response);
        var_dump($record);
    };
};

fclose($phpSocket);

To implement FCGI server, just create a socket and make request-response loop

use Lisachenko\Protocol\FCGI;
use Lisachenko\Protocol\FCGI\FrameParser;
use Lisachenko\Protocol\FCGI\Record;
use Lisachenko\Protocol\FCGI\Record\BeginRequest;
use Lisachenko\Protocol\FCGI\Record\Params;
use Lisachenko\Protocol\FCGI\Record\Stdin;

include "vendor/autoload.php";

$server = stream_socket_server("tcp://127.0.0.1:9001" , $errorNumber, $errorString);

// Just take the first one request and process it
$phpSocket = stream_socket_accept($server);

$response = '';
while ($partialData = fread($phpSocket, 4096)) {
    $response .= $partialData;
    while (FrameParser::hasFrame($response)) {
        $record = FrameParser::parseFrame($response);
        var_dump($record);
    };
};

// We don't respond correctly here, it's a task for your application

fclose($phpSocket);
fclose($server);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].