Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ public function stop() {
fclose($this->pipes[1]);
fclose($this->pipes[2]);

if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
exec('kill -15 ' . $this->pid);
} else {
$binary_pid = proc_get_status($this->handle)['pid'];
$wmic_output = shell_exec('wmic process where (ParentProcessId='. $binary_pid. ') get Caption,ProcessId');
preg_match_all('!\d+!', $wmic_output, $possible_pids);
if(!empty($possible_pids[0][0])) {
exec("taskkill /F /PID ". $possible_pids[0][0]);
}
}

proc_terminate($this->handle);
while($this->isRunning())
Expand Down
34 changes: 22 additions & 12 deletions lib/LocalBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public function __destruct() {

public function binary_path() {
$dest_parent_dir = $this->get_available_dirs();
$binary_path = $dest_parent_dir. "/BrowserStackLocal";
$dest_binary_name = "BrowserStackLocal";
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$dest_binary_name = $dest_binary_name. ".exe";
}
$binary_path = $dest_parent_dir. "/". $dest_binary_name;
if(file_exists($binary_path)){
return $binary_path;
}
Expand Down Expand Up @@ -50,14 +54,14 @@ private function server_home() {

private function platform_url(){
if (PHP_OS == "Darwin")
return 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-darwin-x64';
return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-darwin-x64';
else if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
return 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-win32.exe';
return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal.exe';
if ((strtoupper(PHP_OS)) == "LINUX") {
if (PHP_INT_SIZE * 8 == 64)
return 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-linux-x64';
return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-x64';
else
return 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-linux-ia32';
return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-ia32';
}
}

Expand All @@ -66,18 +70,24 @@ public function download_binary($path) {
if (!file_exists($path))
mkdir($path, 0777, true);

$ch = curl_init();

$dest_binary_name = "BrowserStackLocal";
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$dest_binary_name = $dest_binary_name. ".exe";
}
$dest_binary_path = $path. '/'. $dest_binary_name;
$file = fopen($dest_binary_path , "w+");
$ch = curl_init("");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $file);
$data = curl_exec ($ch);
curl_close ($ch);

$file = fopen($path . '/BrowserStackLocal', "w+");
fputs($file, $data);
fclose($file);

chmod($path . '/BrowserStackLocal', 0755);
return $path . "/BrowserStackLocal";
fclose($file);
chmod($dest_binary_path, 0755);
return $dest_binary_path;
}

private function get_available_dirs() {
Expand Down
5 changes: 4 additions & 1 deletion tests/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ public function test_checkPid() {
public function test_multiple_binary() {
$this->bs_local->start(array('v' => true));
$bs_local_2 = new Local();
$log_file2 = getcwd(). '/log2.log';
print($log_file2);
try {
$bs_local_2->start(array('v' => true));
$bs_local_2->start(array('v' => true, 'logfile' => $log_file2));
$this->fail("Expected Exception has not been raised.");
} catch (LocalException $ex) {
$emessage = $ex->getMessage();
$this->assertEquals(trim($emessage), 'Error: Either another browserstack local client is running on your machine or some server is listening on port 45691');
unlink($log_file2);
return;
}
}
Expand Down