0

I'm trying to reduce the overhead on our database server. I use a php script to produce sitemaps of all the pages on out site, 80,000.

I want to create a cron job which will run once a week and create static versions of the php sitemap files.

However, I need to loop around and call the sitemap php script and output the contents to a separate file.

How do I output the contents of another php to a file for a cron job ?

EDIT: I'll also need to wait or sleep a while so I don't bring down the server.

EDIT for Arvin for the flow of the PHP script etc

At the moment I have a sitemap.xml file which is a sitemap index file, which has lot of www.mydomain.com/sitemap.php?start=500&max=500

The sitemap.php take between 1 second and 2 seconds to run and I have a lot of them.

What I'd like to do in a new script is ...

New script

-loop from N = 0 to 100

--output sitemap.php&start=N&max=500

--wait 20 seconds

-end loop

0

3 Answers 3

3
php script.php > anotherfile.txt

Or

wget -O- http://yoursite/script.php -o/dev/null > anotherfile.txt
Sign up to request clarification or add additional context in comments.

Comments

1

I would prefer wget too because it can mirror whole sites. But there's also a programmatic way:

copy("http://localhost/sitemap.php", "/tmp/sitemap.html");

1 Comment

One problem I didn't think of, see my edit, I'll need to wait / sleep after each so I don't bring down the server.
0

For your updated details:

for($n=0; $n <= 100; $n++) {
   $output = file_get_contents("http://domain.com/sitemap.php?start={$n}&max=500");
   file_put_contents($file, $output);
   sleep(20);
}

6 Comments

@Jules can you add the flow of the program?
@arvin, I don't understand what you mean ?
@Jules 'Cause you said, sleep/wait is needed so I'm wondering. If you could list the things that the program will do. or how sitemaps, are generated. I'm guessing that one script generates 1 sitemap, and you got a bunch of these script. Are you trying to make one single script that will run the other one by one? And you mean to sleep while each sitemap is generated?
@Jules Is the output just one file? And you are appending the content with each iteration?
@Arvin, good question, I had just planned to output to lots of files. I think the best thing to do is lots of files.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.