Skip to content

Instantly share code, notes, and snippets.

@nkmathew
Last active July 2, 2017 08:40
Show Gist options
  • Save nkmathew/5a5b2b1f120a31d96ad2d4a27a4e5b9d to your computer and use it in GitHub Desktop.
Save nkmathew/5a5b2b1f120a31d96ad2d4a27a4e5b9d to your computer and use it in GitHub Desktop.
Batch script that runs a php dev server by on the next free localhost port
@echo off
:: Runs php dev server and opens the link in the currently running browser starting
:: with Chrome. Used for one-off testing or viewing how a cloned project runs
:: Look for a free port
set /a PORT_NUMBER=8080
:NEXT_PORT
netstat /an | findstr :%PORT_NUMBER% >nul
if %ERRORLEVEL% == 0 (
set /a PORT_NUMBER+=1
goto NEXT_PORT
)
tasklist /fi "imagename eq chrome.exe" | findstr chrome.exe >nul
if %ERRORLEVEL% == 0 (
chrome http://localhost:%PORT_NUMBER%
php -S localhost:%PORT_NUMBER%
)
tasklist /fi "imagename eq firefox.exe" | findstr firefox.exe >nul
if %ERRORLEVEL% == 0 (
firefox http://localhost:%PORT_NUMBER%
php -S localhost:%PORT_NUMBER%
)
chrome http://localhost:%PORT_NUMBER%
php -S localhost:%PORT_NUMBER%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment