2024.8.23
Loading...
Searching...
No Matches
ajax.memcached.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
11
12/**
13 * This script checks the status of the Memcached service, including the port check and service status.
14 * It also retrieves and displays the list of Memcached versions, highlighting the current version.
15 * The final output is encoded in JSON format.
16 *
17 * @global object $bearsamppBins Provides access to various service binaries including Memcached.
18 * @global object $bearsamppLang Provides access to language strings for localization.
19 */
20
21// Initialize the result array with keys 'checkport' and 'versions'.
22$result = array(
23 'checkport' => '',
24 'versions' => '',
25);
26
27// Retrieve the Memcached port number.
28$port = $bearsamppBins->getMemcached()->getPort();
29
30// Retrieve localized text strings for service status.
34
35/**
36 * Check if the Memcached service is enabled and update the 'checkport' status accordingly.
37 * If the service is enabled, check if the port is open and update the status.
38 * If the service is disabled, set the status to disabled.
39 */
40if ($bearsamppBins->getMemcached()->isEnable()) {
41 if ($bearsamppBins->getMemcached()->checkPort($port)) {
42 $result['checkport'] .= '<span class="float-end badge text-bg-success">' . sprintf($textServiceStarted, $port) . '</span>';
43 } else {
44 $result['checkport'] .= '<span class="float-end badge text-bg-danger">' . $textServiceStopped . '</span>';
45 }
46} else {
47 $result['checkport'] = '<span class="float-end badge text-bg-secondary">' . $textDisabled . '</span>';
48}
49
50/**
51 * Retrieve the list of Memcached versions and update the 'versions' status.
52 * Highlight the current version with a primary badge and other versions with a secondary badge.
53 */
54foreach ($bearsamppBins->getMemcached()->getVersionList() as $version) {
55 if ($version != $bearsamppBins->getMemcached()->getVersion()) {
56 $result['versions'] .= '<span class="m-1 badge text-bg-secondary">' . $version . '</span>';
57 } else {
58 $result['versions'] .= '<span class="m-1 badge text-bg-primary">' . $bearsamppBins->getMemcached()->getVersion() . '</span>';
59 }
60}
61
62// Encode the result array in JSON format and output it.
63echo json_encode($result);
$textServiceStopped
$textDisabled
global $bearsamppBins
global $bearsamppLang
$textServiceStarted
const HOMEPAGE_SERVICE_STOPPED
const HOMEPAGE_SERVICE_STARTED
const DISABLED