Newer
Older
WSSSnoop / proxy-to-php-server.sh
0xRoM on 6 Jul 2023 762 bytes Initial commit
  1. #!/bin/bash -x
  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.  
  7. # get a random port -- this could be improved
  8. port=$(shuf -i 2048-65000 -n 1)
  9.  
  10. # start the PHP server in the background
  11. if [[ -d "$(realpath ${1:?Missing path to serve})" ]]; then
  12. php -S localhost:"${port}" -t "$(realpath ${1:?Missing path to serve})" &
  13. else
  14. php -S localhost:"${port}" "$(realpath ${1:?Missing path to serve})" &
  15. fi
  16. pid=$!
  17.  
  18. # try to adjust delay to improve performances
  19. sleep 0.2
  20.  
  21. # proxy standard in to nc on that port
  22. nc localhost "${port}"
  23.  
  24. # kill the server we started
  25. kill "${pid}"
Buy Me A Coffee