Python fastcgi client

I am writing a python tool to monitor a fastcgi application. The only thing I need from fastcgi is to load the ping and status pages (and return some error if it does not work).

There are many libraries (from python-fasctgi bindings to twisted ones) that seem to be capable of this, but most of them are just redundant for my purpose, and many of them will immerse me in additional dependencies, causing some packaging of the problem.

So, are there any simple python fastcgi client implementations / libraries that are easy to install / package (before rpm) or are small enough for distribution with the project.

UPDATE

Thanks to agf, I was able to connect to the fastcgi application and send some kind of request to it. This is nothing more than standard php-fpm. But I can’t get an answer to any location: I try from "/ ping", which should answer 200 OK and "pong" in the body. All I get is a 200 OK response with an empty body for any of my request.

I make a request this way:

def _load_page(self, url): """ load fastcgi page """ fcgi = fcgi_client.FCGIApp(host = self.fcgi_host, port = self.fcgi_port) env = { 'SCRIPT_FILENAME': url, 'QUERY_STRING': url, 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': url, 'REQUEST_URI': url, 'GATEWAY_INTERFACE': 'CGI/1.1', 'SERVER_SOFTWARE': 'ztc', 'REDIRECT_STATUS': '200', 'CONTENT_TYPE': '', 'CONTENT_LENGTH': '0', 'DOCUMENT_URI': url, 'DOCUMENT_ROOT': '/', #'SERVER_PROTOCOL' : ??? 'REMOTE_ADDR': '127.0.0.1', 'REMOTE_PORT': '123', 'SERVER_ADDR': self.fcgi_host, 'SERVER_PORT': str(self.fcgi_port), 'SERVER_NAME': self.fcgi_host } ret = fcgi(env) print ret 

I also had to modify the flup client in stdin handling:

 # Transfer wsgi.input to FCGI_STDIN content_length = int(environ.get('CONTENT_LENGTH') or 0) s = '' while True: chunk_size = min(content_length, 4096) #s = environ['wsgi.input'].read(chunk_size) content_length -= len(s) rec = Record(FCGI_STDIN, requestId) rec.contentData = s rec.contentLength = len(s) rec.write(sock) if not s: break 

Note added s='' instead of s = environ['wsgi.input'].read(chunk_size) , which is part of some wsgi-related material from flup. Therefore, it should send an empty stdin.

In addition, I changed flup to return status, headers, result .

I checked the code for reading the answers, and it seems that everything is in order: there is really an empty body with fpm. I checked the network communications with wirehard, and it seems to me that this is good for me - all parameters are passed.

Any ideas?

UPDATE

The problem was the fastcgi param filtering function: it filtered out many useful parameters, such as DOCUMENT_ROOT, SCRIPT_FILENAME, etc. After that, everything works well.

For everyone who is interested, here is the modified client: https://bitbucket.org/rvs/ztc/src/6ec59525156d/src/ztc/lib/flup_fcgi_client.py , and here is an example of use: https://bitbucket.org/rvs /ztc/src/6ec59525156d/src/ztc/php/fpm.py

+4
source share
1 answer

Although flup used as the fastcgi server, it also includes the fastcgi client.

http://hg.saddi.com/flup-server/file/tip/flup/client/fcgi_app.py

This seems to be a single implementation of a single file with no dependencies. He is licensed.

+3
source

All Articles