Skip to content

Commit 3ee91b3

Browse files
committed
fix: better handling of URL redirection
1 parent 1f1c862 commit 3ee91b3

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,26 @@ systemctl restart php-fpm
4141
The script will send the given PHP file to the PHP-FPM process and echo the response to STDOUT.
4242

4343
```shell script
44-
./php-fqm-cli -f </path/to/php/file> -q "<query_params>" [-connect <connection>] [-m <GET|POST>] [-u <URL>]
44+
./php-fpm-cli -f </path/to/php/file> -q "<query_params>" [-connect <connection>] [-m <GET|POST>] [-u <URL>]
4545
```
4646

4747
Parameters:
4848
| Flag | Description | Default | Example |
4949
| ---- | ----------- | ------- | ------- |
50-
| `-f` | Required path to the PHP file | | `/var/www/html/index.php` |
51-
| `-connect` | Optional PHP-FPM host and port, or path to a socket. | `/run/php-fpm/www.sock` | `127.0.0.1:9000` |
50+
| `-f` | Path to the PHP file | | `/var/www/html/index.php` |
51+
| `-connect` | PHP-FPM host and port, or path to a socket | `/run/php-fpm/www.sock` | `127.0.0.1:9000` |
5252
| `-m` | Request method, GET or POST | GET | |
53-
| `-u` | Optional URL to simulate. Only PHP files directly under the document root are currently supported. You may need to include `/index.php` since we don't have Apache RewriteRules. | | `https://www.mydomain.com/index.php` |
53+
| `-u` | URL to simulate. This must return an status code 200, so make sure this is the canonical URL (i.e., it will not redirect) | | `https://www.mydomain.com/` |
5454

5555

5656
Using query parameters:
5757
```shell script
58-
./php-fqm-cli -f myscript.php -q "param1=val1&param2=val2"
58+
./php-fpm-cli -f myscript.php -q "param1=val1&param2=val2"
5959
```
6060

6161
Using a URL:
6262
```shell script
63-
./php-fqm-cli -f /var/www/html/myscript.php -connect 127.0.0.1:9000 -u https://www.mydomain.com/index.php
63+
./php-fpm-cli -f /var/www/html/index.php -connect 127.0.0.1:9000 -u https://www.mydomain.com/
6464
```
6565

6666
[1]: https://gist.github.com/muhqu/91497df3a110f594b992

php-fpm-cli

100755100644
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ main() {
5656
# extract the protocol
5757
proto="$(echo $PHP_URL | grep :// | sed -e's,^\(.*://\).*,\1,g')"
5858

59+
if [[ $proto =~ https ]]
60+
then
61+
https="on"
62+
fi;
63+
5964
# remove the protocol -- updated
6065
url_no_proto=$(echo $PHP_URL | sed -e s,$proto,,g)
6166

@@ -85,9 +90,10 @@ main() {
8590
SERVER_NAME=$host \
8691
REQUEST_URI=/$path \
8792
SCRIPT_FILENAME=$PHP_FILE_PATH \
93+
HTTPS=$https \
8894
QUERY_STRING=$PHP_QUERY_STRING \
8995
REQUEST_METHOD=$PHP_REQUEST_METHOD \
90-
`which cgi-fcgi` -bind -connect "$CONN" > $TMP_OUTPUT_FILE_PATH #without dumping to file, cgi-fcgi hides "Status"
96+
cgi-fcgi -bind -connect "$CONN" > $TMP_OUTPUT_FILE_PATH #without dumping to file, cgi-fcgi hides "Status"
9197

9298
#Get successful-execution indications
9399
php_exit_code=$?;

0 commit comments

Comments
 (0)