Search code examples
phpcronplesk

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


I am trying to write a file in my VPS server. I am using a simple script who works perfectly in my localhost, but not running as PLESK scheduled task.

PHP scripts is as follows

<?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;
}
?>

The script runs. No error, but no file writed.

What am I doing wrong?


Solution

  • Can you set absolute path for the $saveTo and check ? Example,

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