0

I have TeamSpeak3 installed don my server and I want to make a small script that shows if TS3 is up or down

Configuration :

CentOS 7 Php 5.6.24

I tried this script but didn't work for me :

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

    echo "ts3server is not running!";
}

when I echo the $pids I get nothing it's empty, and when I run the command "pgrep ts3server" I get this result : 11149.

Added Info:

Yes I have root access, and I think that exec isn't installed because I don't get any results from this :

<?php
if(function_exists('exec')) {
    echo "exec is enabled";
}

echo exec('whoami');
?>

I tried to enable but can't find nothing about in php.ini!

halfer
  • 19,824
  • 17
  • 99
  • 186
Dolomats
  • 51
  • 2
  • 11

1 Answers1

-1

I'm assuming the 'ts3server' is the name of the process for teamspeak?

Try the snippet below.

$var = exec('pgrep ts3server', $pids);
var_dump($pids, $var);

If that doesn't work maybe remove the pgrep part.

$var = exec('ts3server', $pids);
var_dump($pids, $var);

If that doesn't work it might be that the exec() command is disabled, you could try using backticks.

$var = `pgrep ts3server`;
var_dump($var);
Sunil
  • 155
  • 2
  • 6
  • Why back-ticks for the string? – Script47 Aug 06 '16 at 22:39
  • backticks is an execution operator in php. [Execution Operators](http://php.net/manual/en/language.operators.execution.php) – Sunil Aug 06 '16 at 22:41
  • Ah, did not know that. – Script47 Aug 06 '16 at 22:41
  • Thanks for the help but the 3 of them are giving NULL and when using the pgrep ts3server command I get the id – Dolomats Aug 06 '16 at 22:43
  • As some people have stated it could be a permission issue. Is this on a machine you have full access to (root privileges)? – Sunil Aug 06 '16 at 22:47
  • Edited my post and Added info – Dolomats Aug 06 '16 at 23:11
  • Hmm, open up your php.ini file and look for a line with "disable_functions" if the exec or shell_exec commands are listed then, copy and paste the same line underneath, comment out the original and then remove the two functions I mentioned and save the ini file and try again. – Sunil Aug 06 '16 at 23:24
  • yeah I checked for this too, disable_functions = is empty – Dolomats Aug 06 '16 at 23:27
  • Are you running the script from a web interface or from the CLI? – Sunil Aug 06 '16 at 23:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120334/discussion-between-dolomats-and-sunil). – Dolomats Aug 06 '16 at 23:51