hakkikonu hakkikonu - 1 year ago 69
PHP Question

Is there a way for shutting down pc using PHP

I have an idea, and i have a single php local web page running on localhost

and i want to use GUI for 3 buttons : shut down , sleep and restart

Is PHP allows to me for these operations? Are there ready to write classes, methods in PHP?

Answer Source

If your Apache/PHP configuration is setup to allow the use of system, then you can use that.

For *nix systems:

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

For Windows:

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

More info here.

As far as sleep/standby on *nix is concerned, it varies a lot.

Note: You can also use shell_exec() or exec().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download