【发布时间】:2015-07-28 03:39:35
【问题描述】:
我有一个 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 research@pdrlabs.net"
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 监控进程执行,但找不到正在启动的进程。
【问题讨论】:
标签: php perl shell debian exec