我正在尝试使用 shell_exec 运行 bash 脚本,但它似乎不起作用。(似乎什么也没发生)我正在使用 nginx 和最新的 php5-cgi。下面是 php 文件的样子:
<?php
$startserver = "./startserver.sh";
$startserver = shell_exec($startserver);
$getprocess = "pidof hlds_amd";
$pid = shell_exec($getprocess);
$fh = fopen('closeserver.sh', 'w');
$command = "kill -9 $pid";
fwrite($fh, $command);
fclose($fh);
$string = "at -f closeserver.sh now + 1 hour";
$closer = shell_exec($string);
?>
这就是 bash 脚本的样子:
#!/bin/bash
cd /home/kraffs/srcds
./hlds_run -game cstrike -autoupdate +maxplayers 12 +map de_dust2 > hlds.log 2>&1 &
phpscript 中没有错误,文件创建得很好,但 $startserver 似乎没有被执行并且 $pid 为空。我错过了 php 文件中的某些内容还是需要更改用户的权限?谢谢你的帮助。