PHP command to run a script and save resulting code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sgreer
Forum Newbie
Posts: 2
Joined: Tue Nov 02, 2010 7:13 pm

PHP command to run a script and save resulting code

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

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

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
sgreer
Forum Newbie
Posts: 2
Joined: Tue Nov 02, 2010 7:13 pm

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

Post 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
Post Reply