What potential pitfalls should be considered when using exec() function in PHP for server status checks?
When using the exec() function in PHP for server status checks, potential pitfalls to consider include security risks such as command injection if user input is not properly sanitized, as well as performance issues if the executed command is resource-intensive. To mitigate these risks, always validate and sanitize user input before passing it to exec(), and consider using more secure alternatives like shell_exec() or proc_open().
// Example of using shell_exec() instead of exec() for server status checks
$command = "ping -c 4 google.com";
$output = shell_exec($command);
echo "<pre>$output</pre>";