tags:

views:

61

answers:

3

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?

Thanks in advance!

+1  A: 

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.

Felix Kling
thanks, didn't even know there is anything like that in php :)
n00b
+1  A: 

file_get_contents() would do the trick.

sshow
that did the trick! thanks
n00b
+1  A: 

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.

Palantir