有没有一种方法可以使用PHP关闭PC [英] Is there a way for shutting down pc using PHP
问题描述
我有个主意,我有一个在本地主机上运行的php本地网页
I have an idea, and i have a single php local web page running on localhost
,我想使用GUI的3个按钮:关闭, sleep 和 restart
and i want to use GUI for 3 buttons : shut down , sleep and restart
PHP是否允许我执行这些操作?准备好用PHP编写类和方法了吗?
Is PHP allows to me for these operations? Are there ready to write classes, methods in PHP?
推荐答案
如果您的Apache / PHP配置已设置为允许使用 system
,那么您可以使用它。
If your Apache/PHP configuration is setup to allow the use of system
, then you can use that.
对于* 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
就* nix上的睡眠/待机而言,差异很大。
As far as sleep/standby on *nix is concerned, it varies a lot.
注意:您还可以使用 shell_exec()
或 exec()
。
编辑:
每个用户1597430的注释,在* nix系统中,您可以传递 -h
(暂停)选项,该选项实际上将关闭并暂停 CPU,但不断开主电源。
Per user1597430's comment, in *nix systems you can pass the -h
(halt) option which will essentially shut down and halt the CPUs but not disconnect the main power.
system('shutdown -h now'); // shutdown and halt
system('shutdown -P now'); // shutdown and power off
服务器故障在此方面有很好的答案。
这篇关于有没有一种方法可以使用PHP关闭PC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!