- #!/bin/bash
-
- # Taken from: https://gist.github.com/Jiab77/4d3c1abeb9be4119f33031750cf580d4
- # Increasing local web server performances as possible
- # https://stackoverflow.com/questions/39842170/load-balancing-php-built-in-server/47103758#47103758
- # https://www.php.net/manual/en/features.commandline.webserver.php
-
- # Config
- LISTEN_INTERFACE="127.0.0.1"
- LISTEN_PORT=8082
- ENTRY_POINT=$1
-
- # Detect server type to use
- PHP_SRV_TYPE=$(php -r "if (version_compare(phpversion(), '7.4', '<')) { echo 'tcpserver'; } else { echo 'embedded'; }")
-
- # Run detected server type
- if [[ $PHP_SRV_TYPE == 'embedded' ]]; then
- if [[ -d $ENTRY_POINT ]]; then
- PHP_CLI_SERVER_WORKERS=$(nproc) php -S ${LISTEN_INTERFACE}:${LISTEN_PORT} -t $ENTRY_POINT
- else
- PHP_CLI_SERVER_WORKERS=$(nproc) php -S ${LISTEN_INTERFACE}:${LISTEN_PORT} $ENTRY_POINT
- fi
- else
- tcpserver -v -1 0 ${LISTEN_PORT} ./proxy-to-php-server.sh $ENTRY_POINT
- fi