使用php从itunes获取销售报告

This code is use to get sales report from itunes.

when i run this code through browser refresh it works but when i put this code in cron jobs it not create any files so it can not store data

$logText = '';
$ch1 = curl_init();
$startTime = strtotime('10 days ago');

$today = time();
while ($startTime < $today)
{
    process($startTime);
    $startTime = strtotime('+1 day', $startTime);
}
curl_close ($ch1);

// start process function

function process($time) {

global $logText;
$date = date('Ymd', $time);

global  $ch1, $accounts;
$accounts = array(array('username' => 'xxx',
    'password' => 'xxx',
    'vndnumber' => 'xxx',
),);
foreach($accounts as $account)
{
    $fields_string = "USERNAME=" . urlencode($account['username']);
    $fields_string .= "&PASSWORD=" . urlencode($account['password']);
    $fields_string .= "&VNDNUMBER=" . $account['vndnumber'];
    $fields_string .= "&TYPEOFREPORT=Sales";
    $fields_string .= "&DATETYPE=Daily";
    $fields_string .= "&REPORTTYPE=Summary";
    $fields_string .= "&REPORTDATE=$date";

    $filename = "{$date}-{$account['vndnumber']}";

    **$fp = fopen("$filename.gz", 'w');
    //set the url, number of POST vars, POST data
    curl_setopt($ch1, CURLOPT_URL, 'https://reportingitc.apple.com/autoingestion.tft');
    curl_setopt($ch1, CURLOPT_POST, 7);
    curl_setopt($ch1, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch1, CURLOPT_HEADER, 0);
    curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch1, CURLOPT_FILE, $fp);
    //execute post
    $contents = curl_exec ($ch1);
    //$logText .= $contents; 
    if ($contents  === false)
    {
        echo 'Curl error: ' . curl_error($ch1);
    }
    $logText .= curl_error($ch1);

    fclose($fp);**

    if (filesize("$filename.gz"))
    {
        if (function_exists('gzdecode')) {
            file_put_contents($filename, gzdecode(file_get_contents("$filename.gz")) );
        } else {
            exec("gunzip $filename.gz");
        }

    }

}
file_put_contents(__DIR__."/log_backup.txt",file_get_contents(__DIR__."/log_backup.txt").$logText); }