Last active
July 2, 2017 08:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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