duanhong1985 2011-02-03 10:59
浏览 87
已采纳

PHP,如何将另一个php文件创建的内容输出到文件?

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

  • 写回答

3条回答 默认 最新

  • dongsilu2237 2011-02-03 11:11
    关注

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法