如何从一个PHP脚本

如何从一个PHP脚本

本文介绍了如何从一个PHP脚本(例如批处理文件)中运行多个PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从另一个PHP脚本(例如批处理文件)中运行多个PHP脚本?如果我理解包含在做什么,我认为包含不会起作用.因为我正在运行的每个文件都会重新声明一些相同的功能,等等.我想要的是执行每个新的PHP脚本,就像在一个干净,新鲜的堆栈中一样,而无需了解变量,函数等.来了.

How can I run several PHP scripts from within another PHP script, like a batch file? I don't think include will work, if I understand what include is doing; because each of the files I'm running will redeclare some of the same functions, etc. What I want is to execute each new PHP script like it's in a clean, fresh stack, with no knowledge of the variables, functions, etc. that came before it.

更新:我应该提到脚本是在Windows上运行的,而不是在Web服务器上运行的.

Update: I should have mentioned that the script is running on Windows, but not on a web server.

推荐答案

您可以使用 exec()函数将每个脚本作为外部命令来调用.

You could use the exec() function to invoke each script as an external command.

例如,您的脚本可以执行以下操作:

For example, your script could do:

<?php

exec('php -q script1.php');
exec('php -q script2.php');

?>

Exec周围有一些安全问题,但听起来可能对您有用.

Exec has some security issues surrounding it, but it sounds like it might work for you.

这篇关于如何从一个PHP脚本(例如批处理文件)中运行多个PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:21