The file path for my script is
/var/www/html/MyProject/index.php
when I run the script as
~/./Myproject$ php index.php
its runs perfectly
When I run the script as
~$ php /var/www/html/MyProject/index.php
It does not read the phpseclib file path
My index.php file is
<?php
include("crud.php");
include("functions.php");
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include('Net/SFTP.php');
...
?>
error:
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
How to run the php script form cron job?
From the error message, you can see that phpseclib
is not being added to the include path correctly. Try this for the set_include_path instead:
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR . 'phpspeclib');
The __DIR__
will take into account the location of the file you're executing, rather than trying to find phpspeclib
relative to the current working directory.
You can try placing phpseclib1.0.12 library to the /usr/share/ or if you are running from the Project then you can try adding like this:
set_include_path('/var/www/html/phpseclib1.0.12');
include('Net/SFTP.php');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.