Under the Linux system, using cron to execute PHP programs regularly is a convenient way to deal with it. I recently tested a PHP script and the browser called and debugged everything normally. So I configured the shell timing, but the next day I found that nothing was saved in the database... ...Looking at the error log, it was said that there was an error in a certain line of PHP. I checked this line of code and found that it was a relative reference. This script had also been executed regularly before. The executed program and the referenced file were in the same folder. The reference was written directly. I found the file name and there was no problem. I planned the directory the day before and changed the reference to an absolute reference of ../filename. Unexpectedly, this was the problem. The error showed that it was parsed to the directory of the php server. .

solution:

Add two lines of code to switch directories:

$cur_dir = dirname(__FILE__); //获取当前文件的目录
chdir($cur_dir); //把当前的目录改变为指定的目录
require(../a.php); //引入相对路径文件


Leave a Reply