我有一个php脚本,应该在机器上执行一个perl脚本并打印进程ID。执行它时,我发现进程ID已打印出来,但是在检查进程列表时,我找不到perl脚本的正在运行的进程。
我将该命令记录到一个文件中,发现该命令是正确的,并且从shell执行该命令可以正确执行该脚本。这两个脚本均归www-data所有。
if (isset($_GET['path'])) {
$spath=$_GET['path'];
$cmd="/usr/bin/perl ".getcwd().'/rotten2torrent.pl "'.$spath.'"';
$outputfile="tmpfile";
$pidfile="pid";
if (isset($_GET['recursion'])) {
$recursion=1;
$cmd=getcwd().'/htmlrscrape.pl '.$spath;
} else {
$recursion=0;
}
$command = $cmd . ' > /dev/null 2>&1 & echo $!; ';
$pid = exec($command, $output, $return);
fwrite($logfile, "\n". "Command: ".$cmd);
print 'Download started with PID '.$pid;
fwrite($logfile, "\n". "Download started with PID ".$pid);
fwrite($logfile, "\n". "Output lines: ".$pid);
fwrite($logfile, "\n". "Return code: ".$return);
foreach ($output as &$value) {
fwrite($logfile, "\n". $value);
}
}
日志文件输出:
#cat dldebug.log
http://www.rottentomatoes.com/top/bestofrt/top_100_horror_movies/?category=10 test
Command: /usr/bin/perl /var/www/rotten2torrent.pl "http://www.rottentomatoes.com/top/bestofrt/top_100_horror_movies/?category=10"
Download started with PID 13147
Output lines: 13147
Return code: 0
13147
Done
我还查看了apache2访问和错误日志,但未显示错误:
tac /var/log/apache2/access.log | less
ip1 - - [16/May/2015:12:18:13 +0530] "HEAD / HTTP/1.1" 200 285 "-" "Cloud mapping experiment. Contact [email protected]"
ip2 - - [16/May/2015:11:54:41 +0530] "GET /dlnow.php?path=http%3A%2F%2Fwww.rottentomatoes.com%2Ftop%2Fbestofrt%2Ftop_100_horror_movies%2F%3Fcategory%3D10&action=test HTTP/1.1" 200 321 "http://199.204.187.162/dlbox.php" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36"
我该如何调试?我假设Shell进程开始执行,但随后被系统终止。如何监视正在显示的错误?
exec不是服务器上php.ini中的禁用功能。我已经在服务器上使用php exec测试了“ ls -l”,并且已执行。
我尝试使用htop监视进程执行,但是找不到启动的进程。
为了调试,我将exec命令更改为 $command = $cmd . ' > debug.log 2>&1';
现在,日志输出显示未找到启动脚本所需的perl模块。我错过了这一点,因为在我的shell中,我在测试时以root用户身份运行。www数据用户无权访问这些模块。
要解决此问题,我必须为www-data创建shell和sudo权限。然后,我以www-data身份登录,使用cpan minus来安装所需的模块,然后注销。现在,脚本开始正常运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句