civil777 Posted November 18, 2009 Share Posted November 18, 2009 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!!! Link to comment https://forums.phpfreaks.com/topic/182050-cron-job-php-script-not-running-correctly/ Share on other sites More sharing options...
rajivgonsalves Posted November 18, 2009 Share Posted November 18, 2009 the problems are with the paths you have to specify absolute paths in your script as your cron will run from root directory / Link to comment https://forums.phpfreaks.com/topic/182050-cron-job-php-script-not-running-correctly/#findComment-960297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.