我有这个使用ssh的php脚本。我在c:\ php目录下安装了我的php。当我从这个目录运行这个脚本时,它可以工作。但是,如果我尝试使用绝对路径从其他目录运行此脚本,它会给我各种错误:
C:\inetpub\wwwroot>c:\php\php c:\php\get_cpu1.php
PHP Warning: require_once(Math/BigInteger.php): failed to open stream: No such file or directory in C:\PHP\Net\SSH2.php on line 746
Warning: require_once(Math/BigInteger.php): failed to open stream: No such file or directory in C:\PHP\Net\SSH2.php on line 746
PHP Fatal error: require_once(): Failed opening required 'Math/BigInteger.php' (include_path='C:/PHP/pear') in C:\PHP\Net\SSH2.php on line 746
Fatal error: require_once(): Failed opening required 'Math/BigInteger.php' (include_path='C:/PHP/pear') in C:\PHP\Net\SSH2.php on line 746
我在这里缺少什么想法?
这是get_cpu1.php的代码
<?php
include('C:/PHP/Net/SSH2.php');
$ssh = new Net_SSH2('server1.example.com');
if (!$ssh->login('user', 'passwd')) {
exit('Login Failed');
}
//echo $ssh->exec('pwd');
$line= $ssh->exec('tail -1 /var/log/messages');
//echo $line;
unset($ssh);
?>
答案 0 :(得分:2)
解决这个问题的一种方法是在脚本中首先cd(__DIR__);
。
如果您的年龄超过PHP 5.3,请改用:cd(dirname(__FILE__));