FastCGI Python3 client
Project description
FastCGI and PHP-FPM Python3 Client
A simple FastCGI Python3 Client
- Compatible with IP:port and unix:// sockets
- Standalone script and Python library
- Python logging integration with debug level
- Response encoding guessing from HTTP headers
Original python2 core code from https://github.com/wuyunfeng/Python-FastCGI-Client/, ported to Python3, bug fixed and improved
Installation
With pip:
pip3 install fcgi-client
Or from source code:
git clone https://github.com/darkpills/fcgi-client
Quickstart: PHP-FPM Client
GET request:
# python3 php-fpm-client.py -t 127.0.0.1:9000 -f /var/www/html/index.php\?toto=1
INFO - Sending GET request to 127.0.0.1:9000 @ /var/www/html/index.php?toto=1
INFO - Received response:
X-Powered-By: PHP/8.3.2
Content-type: text/html; charset=UTF-8
Hello World
POST request with post content in post.txt
# python3 php-fpm-client.py -t 127.0.0.1:9000 -f /var/www/html/index.php\?toto=1 -x POST -s "username=admin&password=admin"
INFO - Sending POST request to 127.0.0.1:9000 @ /var/www/html/index.php?toto=1
INFO - Received response:
X-Powered-By: PHP/8.3.2
Content-type: text/html; charset=UTF-8
Usage:
# python3 php-fpm-client.py -h
usage: php-fpm-client.py [-h] -t TARGET -f FILE [-x METHOD] [-p PARAM] [-s POST] [-m TIMEOUT] [-v]
A simple FastCGI client for Python3
optional arguments:
-h, --help show this help message and exit
-t TARGET, --target TARGET
Target to call, host:port or unix://path
-f FILE, --file FILE PHP-FPM Filepath to call with query string, example: /usr/app/index.php?name=value&name2=value2
-x METHOD, --method METHOD
Method to call, example: GET, POST, PUT, DELETE
-p PARAM, --param PARAM
Parameters in the format KEY=VALUE, multiple allowed
-s POST, --post POST POST body content
-m TIMEOUT, --timeout TIMEOUT
Socket timeout in ms
-v, --verbose Verbose output
Quickstart: FastCGI Client
A raw FastCGI request with 2 parameters:
# python3 fast-cgi-client.py -p SCRIPT_FILENAME=/var/www/html/index.php -p REQUEST_METHOD=GET -t 127.0.0.1:9000
INFO - Loaded 2 parameters
INFO - Sending request to 127.0.0.1:9000
INFO - Received response:
bytearray(b'X-Powered-By: PHP/8.3.2\r\nContent-type: text/html; charset=UTF-8\r\n\r\nHello World')
Usage:
# python3 fast-cgi-client.py -h
usage: fast-cgi-client.py [-h] -t TARGET [-p PARAM] [-s STDIN] [-m TIMEOUT] [-k] [-v]
A simple FastCGI client for Python3
optional arguments:
-h, --help show this help message and exit
-t TARGET, --target TARGET
Target to call, host:port or unix://path
-p PARAM, --param PARAM
Parameters in the format KEY=VALUE, multiple allowed
-s STDIN, --stdin STDIN
STDIN content
-m TIMEOUT, --timeout TIMEOUT
Socket timeout in ms
-k, --keepalive Keepalive
-v, --verbose Verbose output
Use it as a library
PHP-FPM client:
from fcgi_client import PHPFPMClient
client = PHPFPMClient("unix:///my/socket")
# a get request
response = client.get('/var/www/html/index.php', 'test=1&toto=2')
# a post request
response = client.post('/var/www/html/index.php', 'test=1&toto=2')
FastCGI client:
from fcgiclient import FastCGIClient
client = FastCGIClient("unix:///my/socket")
response = client.request({'SCRIPT_FILENAME':'/var/www/html/index.php', 'REQUEST_METHOD': 'GET'}, 'postcontenthere')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fcgi_client-0.0.1.tar.gz.
File metadata
- Download URL: fcgi_client-0.0.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a39edb98cdfef0b4c7e13b5670e99c895927f3886df854c7b509c2f941e4cf4
|
|
| MD5 |
a8eefd18f54e8c33e9c5ab6f23188bee
|
|
| BLAKE2b-256 |
82c4e7da892f6fad6e36f5da28573bfb3df3bca061108c5a27491588c64b5f35
|
File details
Details for the file fcgi_client-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fcgi_client-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80cf9bc5cdccd6bab02cc1eef79d9fc7f9ff01bfeb2fb9e7eeec8db2332d0b64
|
|
| MD5 |
91bc63bdaaa16443610560c481534f70
|
|
| BLAKE2b-256 |
e7927142f5cd0262200afb64d131aead26921026082a3207c358004fba9d87f2
|