Cron Job -- PHP script not running correctly
Posted: Wed Nov 18, 2009 2:04 pm
I am trying to run a php script using Cron, and I am having a problem getting Cron to create a new file. (For those of you not familiar, Cron is a a system program that can execute a script at a specific time).
Here's what I have working: I got Cron to run a script that will read and write my MySQL database.
Here's what is not working: Now I am trying to get Cron to run a script that will generate an Excel file and save it to the server. I am using a PEAR Excel script to do the generation. I am able to generate the Excel file if I run the script in my browser, BUT (and here's my problem) the script will not generate the Excel file if it is run from Cron. I can't figure out why. Here's the script:
File generate_excel_file.php:
(Permissions on this file are set to 777.)
Here's the crontab file:
Anyone know what might be wrong? Thanks for the help!!!
Here's what I have working: I got Cron to run a script that will read and write my MySQL database.
Here's what is not working: Now I am trying to get Cron to run a script that will generate an Excel file and save it to the server. I am using a PEAR Excel script to do the generation. I am able to generate the Excel file if I run the script in my browser, BUT (and here's my problem) the script will not generate the Excel file if it is run from Cron. I can't figure out why. Here's the script:
File generate_excel_file.php:
Code: Select all
#!/usr/bin/php5
<?php
require_once "Spreadsheet/Excel/Writer.php";
// Create an instance
$xls = &new Spreadsheet_Excel_Writer();
// Send HTTP headers to tell the browser what's coming
$xls->send("test.xls");
// Add a worksheet to the file, returning an object to add data to
$sheet = &$xls->addWorksheet('Binary Count');
// Write some numbers
for ($i = 0;$i < 11;$i++) {
// Use PHP's decbin() function to convert integer to binary
$sheet->write($i, 'test', decbin($i));
}
// Finish the spreadsheet, dumping it to the browser
$xls->close();
?>
Here's the crontab file:
Code: Select all
48 2 15 * * /var/www/generate_excel_file.php
Anyone know what might be wrong? Thanks for the help!!!