3

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

some Pseudocode:

if (processExists("notepad.exe")) {
    echo "exists";
} else {
    echo "doesn't exist";
}
8
  • 2
    Isn't PHP web based? I'm pretty sure this isn't actually possible. You're going to have to use C++, if you want to accomplish this. Commented Aug 3, 2016 at 13:04
  • 4
    You would only be able to check server-side processes. JavaScript (client-side) isn't allowed that kind of access because of security. Commented Aug 3, 2016 at 13:05
  • well php can us shell_exec(), so I though that something like this may be possible Commented Aug 3, 2016 at 13:06
  • shell_exec() is on the server. Commented Aug 3, 2016 at 13:06
  • I mean you can run a local .exe with it Commented Aug 3, 2016 at 13:06

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Of my own comment @CaelanGrgurovic
1

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.

Comments

0

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!
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.