2013-07-14 33 views
1

我有一个PHP文件,基于某些参数返回HTML,但它也保存在一个单独的目录(基本上是一个自定义的缓存过程)这个输出。PHP:“运行”文件/脚本而不是包含?

现在我想建立一个单独的php文件,它基于已知可能参数的数组自动更新缓存。

所以我想要“加载”或“运行”而不是“包含”文件多次使用不同的参数,以便它将结果保存在缓存文件夹中。

是否有一个PHP函数,可以让我简单地加载这个其他文件,也许告诉我什么时候完成?如果没有,我是否需要使用ajax来做这样的事情,或者也许PHP的curl库?

目前我在想沿着以下的说法:

<?php 
$parameters = array("option1", "option2", "option3"); 

//loop through parameters and save to cache folder 
foreach ($parameters as $parameter){ 
    //get start time to calculate process time 
    $time_start = microtime(true); 
    sleep(1); 

    //I wish there was some function called run or load similar to jquery's 'load' 
    run("displayindexsearch.php?p=$parameter"); 

    //return total time that it took to run the script and save to cache 
    $time_end = microtime(true); 
    $time = $time_end - $time_start; 
    echo "Process Time: {$time} seconds"; 
} 
?> 

回答

0

你为什么不包含的文件,但创造你想要的文件里做的事情功能。这样,当你想运行的时候,你只需调用函数即可。这似乎是正确的方式来做你想做的事情,如果我正确地理解它。

0

我找到的最好的解决方案是使用:

file_get_contents($url)

那么,问题会查找run的替代品,我代替file_get_contents($url)

请注意,当我在此处使用相对路径时出现错误。我只有在使用http://localhost/displayindexsearch.php?p=parameter等才有成功。