Newer
Older
WSSSnoop / simple-php-webserver.sh
0xRoM on 6 Jul 2023 931 bytes Initial commit
  1. #!/bin/bash
  2.  
  3. # Taken from: https://gist.github.com/Jiab77/4d3c1abeb9be4119f33031750cf580d4
  4. # Increasing local web server performances as possible
  5. # https://stackoverflow.com/questions/39842170/load-balancing-php-built-in-server/47103758#47103758
  6. # https://www.php.net/manual/en/features.commandline.webserver.php
  7.  
  8. # Config
  9. LISTEN_INTERFACE="127.0.0.1"
  10. LISTEN_PORT=8082
  11. ENTRY_POINT=$1
  12.  
  13. # Detect server type to use
  14. PHP_SRV_TYPE=$(php -r "if (version_compare(phpversion(), '7.4', '<')) { echo 'tcpserver'; } else { echo 'embedded'; }")
  15.  
  16. # Run detected server type
  17. if [[ $PHP_SRV_TYPE == 'embedded' ]]; then
  18. if [[ -d $ENTRY_POINT ]]; then
  19. PHP_CLI_SERVER_WORKERS=$(nproc) php -S ${LISTEN_INTERFACE}:${LISTEN_PORT} -t $ENTRY_POINT
  20. else
  21. PHP_CLI_SERVER_WORKERS=$(nproc) php -S ${LISTEN_INTERFACE}:${LISTEN_PORT} $ENTRY_POINT
  22. fi
  23. else
  24. tcpserver -v -1 0 ${LISTEN_PORT} ./proxy-to-php-server.sh $ENTRY_POINT
  25. fi
Buy Me A Coffee