The script below will find out if the Selenium Server (java jar file) is already running in windows.  It uses the Windows Management Instrumentation Command-line (wmic) to look at the processes that are running as “java.exe” and gets the command line that started them.  The php script than Iterates through the command line output and looks for  “selenium-server-standalone”.

If you’re not familiar with Selenium you can learn how to use it with PHP here!

<?
$javaProgramFileName="selenium-server-standalone";
$isSeleniumAlreadyRunning=false;
exec("wmic process where name=\"java.exe\" get commandline",$output);
foreach($output as $line)
{
if(strpos($line, $javaProgramFileName) !== FALSE)
{
$isSeleniumAlreadyRunning=true;
break;
}
}
if(!$isSeleniumAlreadyRunning)
{
//Execute in the background by sending output to NUL
exec("java -jar ".__DIR__."\selenium-server-standalone-2.47.1.jar > NUL");
}
//Selenium is up an running lets use the PHP Selenium Driver
//Example: https://github.com/facebook/php-webdriver/blob/community/example.php