lawrencekm / server-info
一个用于检索服务器信息的软件包
dev-master
2024-02-09 09:32 UTC
Requires (Dev)
- phpunit/phpunit: ^10.5
This package is not auto-updated.
Last update: 2024-10-01 17:57:22 UTC
README
服务器信息包
一个用于监控目的的,用于获取服务器信息和系统服务详情的PHP软件包。
安装
要在您的PHP项目中安装此软件包
composer require lawrencekm/server-info
您也可以克隆仓库或下载源代码。
git clone https://github.com/lawrencekm/server-info.git
使用Composer安装依赖项。
composer install
用法
要使用服务器信息包,请按照以下步骤操作
在您的PHP代码中初始化ServerInfo类。
require __DIR__ . '/vendor/autoload.php';
$serverInfo = new ServerInfo();
Retrieve server information in JSON format.
echo $serverInfo->getServerInformation();
//Optionally, you can render the information as an HTML table.
// echo $serverInfo->getServerInformation(); // Uncomment this line if not already called
$data = json_decode($serverInfo->getServerInformation(), true);
// Render HTML tables
测试
要使用PHPUnit运行测试,请按照以下步骤操作
确保PHPUnit已作为开发依赖项安装。 composer install --dev
运行PHPUnit测试。 ./vendor/bin/phpunit tests
作为Web服务器运行
您可以使用Docker将应用程序作为Web服务器运行。选择以下方法之一
方法1: Dockerfile
创建以下内容的Dockerfile
```
FROM php:8.2-apache
COPY . /var/www/html/
```
构建并运行Docker容器: docker build -t my-server-info . docker run -p 8080:80 -d my-server-info
方法2: 无需Dockerfile
运行以下Docker命令,在浏览器localhost:8080上获取输出
docker run -d -p 8080:80 --name my-server-info-php-app -v "$PWD":/var/www/html php:8.2-apache
通过命令行运行
您也可以通过命令行运行index.php文件以获取JSON响应
php index.php