通过cronjob运行时,file_put_contents不起作用

时间:2020-10-25 17:36:28

标签: php cron cpanel

在我的服务器上,我有一个php文件,我需要每天运行该文件,它将制作大约300个php文件,(替换当前的php文件) 此文件可以正常工作,除非通过cronjob运行,否则不会创建文件。

发生错误时,我已经缩小了位置,但是我不知道为什么,或者如何解决。 我想再说一遍,当从我的浏览器中调用该脚本时,它工作正常。 (但是出于安全性考虑,不可以选择通过wget进行操作)

它认为与“ require_once”或路径有关

3个版本:

版本1:根本不会创建文件,脚本的其余部分也不执行

<?php 
require_once('wp-load.php');require_once('wp-admin/includes/file.php' );
file_put_contents('/path/file.php',"testcontents");
?>

版本2,文件已创建,但脚本的其余部分未执行

<?php 
file_put_contents('/path/file.php',"testcontents");
require_once('wp-load.php');require_once('wp-admin/includes/file.php' );
?>

版本3:文件可以很好地执行,但是不包含file_put_contents,这是我确实需要的东西,因此它只能完成atm的一半工作。

<?php 
require_once('wp-load.php');require_once('wp-admin/includes/file.php' );
?>

再次,问题仅在脚本被称为cronjob时出现,我没有对服务器的root访问权(仅cpanel访问权),在我们拥有的其他服务器上可以正常工作。

编辑: test1.php被创建 test.2php无法创建

<?php 
error_reporting(E_ALL);
file_put_contents('/home/username/public_html/visit/test1.php',"test1");
require_once('wp-load.php');
file_put_contents('/home/username/public_html/visit/test2.php',"test2");

?>

0 个答案:

没有答案