phpsec lib路径无法从cron作业中运行

时间:2015-10-04 11:23:48

标签: php cron phpseclib

我的脚本的文件路径是

/var/www/html/MyProject/index.php

当我以

运行脚本时

~/./Myproject$ php index.php它的运行完美

当我以

运行脚本时
~$ php /var/www/html/MyProject/index.php

它不会读取phpseclib文件路径

我的index.php文件是

<?php

include("crud.php");
include("functions.php");

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include('Net/SFTP.php');

...

?>

错误:

PHP Warning:  include(Net/SFTP.php): failed to open stream: No such file or directory in /var/www/html/MyProject/index.php on line 6
PHP Warning:  include(): Failed opening 'Net/SFTP.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear.:/usr/share/php:/usr/share/pear/phpseclib') in /var/www/html/MyProject/index.php on line 6
PHP Fatal error:  Class 'Net_SFTP' not found in /var/www/html/MyProject/index.php on line 186

如何从cron作业运行php脚本?

2 个答案:

答案 0 :(得分:2)

从错误消息中,您可以看到phpseclib未正确添加到包含路径。请尝试使用set_include_path:

set_include_path(get_include_path() . PATH_SEPARATOR .  __DIR__ . DIRECTORY_SEPARATOR . 'phpspeclib');

__DIR__将考虑您正在执行的文件的位置,而不是尝试查找相对于当前工作目录的phpspeclib

答案 1 :(得分:0)

您可以尝试将phpseclib1.0.12库放置到 / usr / share / ,或者如果您是从Project中运行的,则可以尝试这样添加:

set_include_path('/var/www/html/phpseclib1.0.12');
include('Net/SFTP.php');