Reputation: 6780
I need to periodically pull status information from PHP-FPM. Currently I just parse the output of the following script:
export SCRIPT_NAME=/status
export SCRIPT_FILENAME=/status
export REQUEST_METHOD=GET
/usr/bin/cgi-fcgi -bind -connect /tmp/php5-fpm.sock
However, if possible, I'd like my Python program to actually do the cgi-fcgi
stuff on its own.
I've tried searching for how Python can invoke CGI/FastCGI; unfortunately, all docs I found always talk about how to invoke a Python program via CGI/FastCGI. That is, Python on the 'server' side.
So, how do I implement a CGI/FastCGI 'client' on Python?
(Note that the cgi-fcgi allows direct access to the CGI/FastCGI listener; that's what I'm looking for)
Upvotes: 0
Views: 710
Reputation: 6780
I've voted as duplicate of this question.
Still, I want to document my solution:
fcgi_app
module from flup
(namely, flup.client.fcgi_app)Invocation as simple as the following:
# "flup_fcgi_client.py" is the modified flup.client.fcgi_app module
# located in the same directory
import flup_fcgi_client as fcgi_client
fcgi = fcgi_client.FCGIApp(connect='/path/to/socket')
script = '/status'
query = 'json'
env = {
'SCRIPT_NAME': script,
'SCRIPT_FILENAME': script,
'QUERY_STRING': query,
'REQUEST_METHOD': 'GET'}
code, headers, out, err = fcgi(env)
# Handle return values here...
Upvotes: 1