PHP script - detect whether running under linux or Windows?(PHP 脚本 - 检测是否在 linux 或 Windows 下运行?)
问题描述
我有一个 PHP 脚本,可以放在 windows 系统或 linux 系统上.无论哪种情况,我都需要运行不同的命令.
I have a PHP script that may be placed on a windows system or a linux system. I need to run different commands in either case.
如何检测我所处的环境?(最好是 PHP 而不是聪明的系统黑客)
How can I detect which environment I am in? (preferably something PHP rather than clever system hacks)
为了澄清,脚本是从命令行运行的.
To clarify, the script is running from the command line.
推荐答案
检查 PHP_OS
常量文档.
它将在 Windows 上为您提供各种值,例如 WIN32
、WINNT
或 Windows
.
It will give you various values on Windows like WIN32
, WINNT
or Windows
.
另请参阅:可能的值:PHP_OS 和 php_uname
文档:
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
echo 'This is a server using Windows!';
} else {
echo 'This is a server not using Windows!';
}
这篇关于PHP 脚本 - 检测是否在 linux 或 Windows 下运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 脚本 - 检测是否在 linux 或 Windows 下运行?


基础教程推荐
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的PDF导出 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01