php - 有没有办法使用 PHP 关闭电脑

标签 php windows browser

我有一个想法,我有一个在本地主机上运行的 php 本地网页

我想为 3 个按钮使用 GUI:关闭 sleep 重新启动

PHP 允许我进行这些操作吗?有准备好用 PHP 编写类、方法吗?

最佳答案

如果您的 Apache/PHP 配置设置为允许使用 system,那么您可以使用它。

对于 *nix 系统:

system('shutdown now');    // shutdown
// or
system('reboot');          // reboot
system('shutdown -r now'); // also reboot :)

对于 Windows:

system('shutdown -t -s 0'); // shutdown
// or
system('shutdown -r -t 0'); // reboot

More info here.

就 *nix 上的 sleep /待机而言,变化很大。


注意:您也可以使用shell_exec()exec()


编辑:

根据 user1597430 的评论,在 *nix 系统中,您可以传递 -h(暂停)选项,这实际上将关闭并暂停 CPU,但不会断开主电源.

system('shutdown -h now'); // shutdown and halt
system('shutdown -P now'); // shutdown and power off

服务器故障has some great answers here about this .

关于php - 有没有办法使用 PHP 关闭电脑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13538970/

相关文章:

php - 从 CURL 请求和 file_get_contents 收到的无效 cookie

php - MySQL & PHP 排行榜查询

c++ - 代码块,GCC : change project language c and c++?

html - 平铺一百个 1px 的方 block VS 平铺四个 25px 的方 block

javascript - 处理按键时防止 IE 刷新

php - 用于动态网页的 AJAX VS PHP?

php - CakePHP 无法从 lib 访问 CakeSession

windows - 什么是 Windows 命令行 EXE 的 "side-by-side configuration",我该如何更正它?

c - Win32 剪贴板和 alpha channel 图像

python - 将音频录制从浏览器流式传输到服务器?