Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 lines
1.3 KiB

  1. <?php
  2. /**
  3. * @brief This class contain functions for the database management
  4. *
  5. */
  6. class dbm {
  7. /**
  8. * @brief Return a list of database processes
  9. *
  10. * @return array
  11. * 'list' => List of processes, separated in their different states
  12. * 'amount' => Number of concurrent database processes
  13. */
  14. public static function processlist() {
  15. $r = q("SHOW PROCESSLIST");
  16. $s = array();
  17. $processes = 0;
  18. $states = array();
  19. foreach ($r AS $process) {
  20. $state = trim($process["State"]);
  21. // Filter out all non blocking processes
  22. if (!in_array($state, array("", "init", "statistics", "updating"))) {
  23. ++$states[$state];
  24. ++$processes;
  25. }
  26. }
  27. $statelist = "";
  28. foreach ($states AS $state => $usage) {
  29. if ($statelist != "")
  30. $statelist .= ", ";
  31. $statelist .= $state.": ".$usage;
  32. }
  33. return(array("list" => $statelist, "amount" => $processes));
  34. }
  35. /**
  36. * Checks if $array is a filled array with at least one entry.
  37. *
  38. * @param $array mixed A filled array with at least one entry
  39. * @return Whether $array is a filled array
  40. */
  41. public static function is_result($array) {
  42. // It could be a return value from an update statement
  43. if (is_bool($array))
  44. return $array;
  45. return (is_array($array) && count($array) > 0);
  46. }
  47. }
  48. ?>