2017 © Pedro Peláez
 

library protocol-fcgi

Implementation of FCGI Protocol in PHP

image

lisachenko/protocol-fcgi

Implementation of FCGI Protocol in PHP

  • Saturday, December 5, 2015
  • by lisachenko
  • Repository
  • 9 Watchers
  • 60 Stars
  • 6,455 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 5 Versions
  • 96 % Grown

The README.md

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., (*1)

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, (*2)

Build Status Scrutinizer Code Quality Code Coverage Packagist Minimum PHP Version License, (*3)

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., (*4)

To install this library, just write, (*5)

``` bash $ composer require lisachenko/protocol-fcgi, (*6)


After that you can use an API to parse/create FCGI requests and responses. Simple FCGI-client: ```php <?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, (*7)


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);

The Versions

05/12 2015

dev-master

9999999-dev

Implementation of FCGI Protocol in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Alexander Lisachenko

05/12 2015

1.1.1

1.1.1.0

Implementation of FCGI Protocol in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Alexander Lisachenko

05/12 2015

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1

Implementation of FCGI Protocol in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Alexander Lisachenko

23/10 2015

1.1.0

1.1.0.0

Implementation of FCGI Protocol in PHP

  Sources   Download

MIT

by Alexander Lisachenko

08/09 2015

1.0.0

1.0.0.0

Implementation of FCGI Protocol in PHP

  Sources   Download

MIT

by Alexander Lisachenko