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 下运行?
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
