当我在Plesk的预定任务中运行PHP脚本时,目录是不同的

时间:2017-11-01 10:47:48

标签: php scheduled-tasks plesk

我使用此clear.php脚本删除正确的clear目录中的所有文件和文件夹:

<?php
 function deleteDir($dirPath) {
    if (! is_dir($dirPath)) {
        throw new InvalidArgumentException("$dirPath must be a directory");
    }
    if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
        $dirPath .= '/';
    }
    $files = glob($dirPath . '*', GLOB_MARK);
    foreach ($files as $file) {
        if (is_dir($file)) {
            deleteDir($file);rmdir($file);
        } else {
            unlink($file);
        }
    }

}
deleteDir('clear');
?>

当我运行代码mydomain.com/clear.php时,它可以工作并删除所有文件和文件夹,但是当我在plesk中创建计划任务并使用此代码时,它会显示:

  

任务&#34; httpdocs / clear.php&#34;在0秒内完成错误。看到   细节

当我点击它显示的see details时:

Task "httpdocs/clear.php" completed with error in 0 seconds, output:

PHP Fatal error: Uncaught InvalidArgumentException: clear must be a directory in /var/www/vhosts/domain_name.com/httpdocs/clear.php:4
Stack trace:
#0 /var/www/vhosts/domain_name.com/httpdocs/clear.php(19): deleteDir('clear')
#1 {main}
thrown in /var/www/vhosts/domain_name.com/httpdocs/clear.php on line 4  

0 个答案:

没有答案