开发者

PHP, how do I output the the contents created by another php file to file?

开发者 https://www.devze.com 2023-02-08 02:21 出处:网络
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'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


php script.php > anotherfile.txt

Or

wget -O- http://yoursite/script.php -o/dev/null > anotherfile.txt


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");


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消