Page 1 of 1

PHP command to run a script and save resulting code

Posted: Tue Nov 02, 2010 7:23 pm
by sgreer
Hi there

Currently I have a script which runs every hour via cron. The command I'm using is "php /var/www/html/news.php > /var/www/html/index.html".

I have a couple of issues with this:
1) It seems to add the line "Content-type: text/html" to the very top of the HTML file when it's generated.
2) The script reads quite a lot of data and takes about 3 minutes to run. The page is built gradually and looks broken for 3 minutes of every hour, until the script has finished and the page is fully built.

What I'd like to do is replace this cron command and execute a php file that perhaps does the following:
1) executes the script
2) saves it to a file index-temp.html
3) waits 3 minutes until the file has fully finished
4) overwrites the previous index.html with the new one.

Can anyone suggest what the best practice would be, and what code I might use to do it?

Thanks in advance for your help.

Re: PHP command to run a script and save resulting code

Posted: Tue Nov 02, 2010 9:55 pm
by s.dot
I would eliminate the output part of the crontab command (" > /var/www/html/index.html") and have your news.php script write to that file using php instead.

By doing this, you can either write the contents to index.html all at once after the script is done doing its thing, or you can write to a temp file and have php copy it over to index.html once it's done.

Re: PHP command to run a script and save resulting code

Posted: Wed Nov 03, 2010 10:05 am
by sgreer
Thanks. Is there much code? I don't know how to do it myself, would it require hiring a developer do you reckon?

Cheers

Simon