如何批量处理需要很长时间才能执行的PHP脚本?

如何批量处理需要很长时间才能执行的PHP脚本?

问题描述:

I've built a PHP script that creates/restores a backup containing a sites content and database. It works really well on smaller sites but it runs into trouble on larger sites. What would be the best way to batch a script like this? Basically, it copies files from one directory to another, creates a DB dump and then zips the directory.

I've done a little bit of research, do I need to use cron jobs?

我已经构建了一个PHP脚本,用于创建/恢复包含网站内容和数据库的备份。 它在较小的网站上运行良好,但在较大的网站上遇到麻烦。 批处理这样的脚本最好的方法是什么? 基本上,它将文件从一个目录复制到另一个目录,创建数据库转储然后压缩目录。 p>

我做了一些研究,是否需要使用cron作业? p> div>

If it is something that happens at a fixed time / schedule, then it should be a cron job. This is fairly straightforward to set up. There are plenty of tutorials.

If, on the other hand, it is an action a user triggers from a web browser, you should fork and exec. You take in the user's input, fork and exec and then let the user know that he will be emailed when the process is complete.