php /home/test9/public_html/degerlendir/test-4567.php "var1=18&var2=22"
我需要使用 cron 作业在后台运行一个页面。我用上面的命令测试了我的代码。但是我得到这个错误:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/extensions/no-debug-non-zts-20100525/imagick.so' - /usr/lib64/extensions/no-debug-non-zts-20100525/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: require_once(../config.php): failed to open stream: No such file or directory in /home/test9/public_html/degerlendir/test-4567.php on line 2
PHP Fatal error: require_once(): Failed opening required '../config.php' (include_path='.:/usr/lib64/php') in /home/test9/public_html/degerlendir/test-4567.php on line 2
问题是页面在父目录中不包含 config.php。该页面在浏览器中正常工作。我尝试使用不同的 require_once 变体,例如 require_once ($_SERVER['DOCUMENT_ROOT']."/config.php")。我无法让它工作。
最佳答案
命令行中没有 $_SERVER['DOCUMENT_ROOT']
.那个只能从 http 服务器 (Apache) 获得。
工作目录不会自动设置。如果您提示当前位于/some/path/脚本将尝试在/some/config.php 中查找 config.php。
使用 __DIR__
尝试 cd 到当前路径在脚本的开头
<?php chdir(__DIR__); ?>
关于php - require_once 在命令行中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45692982/