且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

相对路径在 cron PHP 脚本中不起作用

更新时间:2023-02-09 23:27:45

从 cron 运行时,脚本的工作目录可能不同.此外,关于 PHP 的 require() 和 include() 存在一些混淆,这导致了工作目录真正是问题所在的混淆:

The working directory of the script may be different when run from a cron. Additionaly, there was some confusion about PHPs require() and include(), which caused confusion about the working directory really being the problem:

include('foo.php') // searches for foo.php in the same directory as the current script
include('./foo.php') // searches for foo.php in the current working directory
include('foo/bar.php') // searches for foo/bar.php, relative to the directory of the current script
include('../bar.php') // searches for bar.php, in the parent directory of the current working directory