我在本地运行一个脚本,完成后对远程服务器上的脚本执行exec调用。
exec("ssh [email protected] \"php /full/path/to/script.php\"", $output, $return);
它向我提出了这个错误:
PHP Warning: require(../resources/vendor/autoload.php): failed to open stream: No such file or directory in /full/path/to/script.php on line 3
我已经尝试将所需的脚本收费到它的完整路径但没有成功。有任何想法吗?
因为PHP将CWD(当前工作目录)设置为SSH登录后的位置(可能是用户主文件夹),并且PHP文件中对包含的引用被解释为相对于CWD。您应该将目录更改为项目的根目录:
exec("ssh [email protected] \"cd /full/path/to/; php script.php\"", $output, $return);