开发者

Execute PHP file

Alright this probably sounds easier than it is :)

I've got two files:

file1.php
file2.php

Withing my file1.php is a loop and within that loop i'd like to execute (not include) 开发者_开发问答file2.php.

while(1){ //execute file2.php }

I know i could use exec() or wrap file2.php into a function but is there a native function to do something like this?


And why shouldn't an "include()" work?

If you need, you could perform some ambient sanitization or initialization before. If you included the file in a function's body, for example, all the local variables would be masked. You'd still need to move session contents, for example, but that's easy...

Otherwise, you could still launch the php interpreter (exec php passing it the script as argument). It's easier to make a wrapper bash script for that.


file_get_contents() should do the trick.


If really necessary, you can use backticks. E.g.:

$output = `php file2.php`;

But I would encapsulate the functionality in file2.php in a function, include the file once and run this function in your loop. This is a much cleaner approach imho.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜