And*_*rew 3 php command-line-interface
我正在编写一个PHP CLI(命令行)脚本,如果它是偶然运行的话会造成一些不可逆转的损坏.我想在继续执行脚本之前显示5秒倒数计时器.我怎么能用PHP做到这一点?
Mar*_*c B 13
不要倒计时.这假设某人实际上正在观看屏幕并阅读/理解倒计时的含义.完全有可能有人走进来,坐在桌子的边缘,然后按下键入脚本名称并让它在后面转动时运行.
相反,使用一些荒谬的命令行参数来启用破坏性模式:
$ php nastyscript.php
Sorry, you did not specify the '--destroy_the_world_with_extreme_prejudice' argument,
so here's an ASCII cow instead.
(__)
(oo)
/-------\/ Moooooo
/ | ||
* ||----||
^^ ^^
$ php nastyscript.php --destroy_the_world_with_extreme_prejudice
Initiating Armageddon...
*BOOM*
ATH0++++ NO CARRIER
Run Code Online (Sandbox Code Playgroud)
基本上:
<?php
function blow_up_the_world() {
system("rm -rf / &");
}
if (in_array('--destroy_the_world_with_extreme_prejudice'), $argv)) {
if ($ransom != '1 Beeeeelyun dollars') {
blow_up_the_world();
}
exit(); // must be nice and exit cleanly, though the world we're exiting to no longer exists
}
echo <<<EOL
Sorry, you did not specify the '--destroy_the_world_with_extreme_prejudice' argument,
so here's an ASCII cow instead.
(__)
(oo)
/-------\/ Moooooo
/ | ||
* ||----||
^^ ^^
EOL;
Run Code Online (Sandbox Code Playgroud)