如何在 PLESK 中使用 PHP 计划任务写入文件?

How to write a file ussing PHP schedule task in PLESK ?

我正在尝试在我的 VPS 服务器中写入一个文件。我正在使用一个简单的脚本,它在我的本地主机上完美运行,但不是 运行 作为 PLESK 计划任务。

PHP脚本如下

<?php
$fileUrl = 'http://xxxxremotefile.kml';
$saveTo = 'myfile.kml';

$fp = fopen($saveTo, 'w+');
if($fp === false){
    throw new Exception('Could not open: ' . $saveTo);
}
$ch = curl_init($fileUrl);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_exec($ch);
if(curl_errno($ch)){
    throw new Exception(curl_error($ch));
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($statusCode == 200){
    echo 'Downloaded!';
} else{
    echo "Status Code: " . $statusCode;
}
?>

脚本运行。没有错误,但没有写入文件。

我做错了什么?

你能为 $saveTo 设置绝对路径并检查吗?例如,

$saveTo = '/home/myfile.kml';