Jump to content

Cron Job -- PHP script not running correctly


civil777

Recommended Posts

 

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:

 


#!/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();
?> 

 

(Permissions on this file are set to 777.)

 

Here's the crontab file:


48 2 15 * * /var/www/generate_excel_file.php

 

 

Anyone know what might be wrong?  Thanks for the help!!!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.