utdev
utdev

Reputation: 4102

Php check if executable is running

Is it possible in Php to check wether an executable is running or not,

some Pseudocode:

if(processExists("notepad.exe")
{
     echo "exists";
}
{
     echo "doesn't exists";
}

Upvotes: 3

Views: 1346

Answers (3)

typeo.top
typeo.top

Reputation: 15

This an easy way to check if a proccess is running on Windows using PHP:

exec("tasklist 2>NUL", $task_list);

//print_r($task_list);

foreach ($task_list as $task) {

    if (strpos($task, 'MSWC.exe') !== false) { echo " MSWC.exe is running "; }
  
  }

For linux you can use:

exec("pgrep lighttpd", $pids);
if(empty($pids)) {

    // lighttpd is not running!
}

Upvotes: 0

Exagone313
Exagone313

Reputation: 115

I understand you are using cli or want to check server-side processes.

For a Windows-specific solution, you can execute the shell command tasklist with the proper options (see tasklist /?). On Unix-based, you would use ps.

To execute a shell command under PHP, you can use shell_exec() or exec().

Warning: Do not enter not sanitized user input in these commands.

Upvotes: 1

Jay Blanchard
Jay Blanchard

Reputation: 34426

You would only be able to check server-side processes, where PHP is running. JavaScript (client-side) isn't allowed that kind of access because of security.

Upvotes: 4

Related Questions