问题
virtual()
can be used only when running PHP as an apache module. My shared hosting runs it as CGI so it doesn't work. Is there any other method to do it?
Note: the subrequest is for static files that I'd like to let Apache serve (for performance, HTTP-headers caching, etc.). Right now this is handled by using an HTTP redirect (that I want to get rid of) issued by the PHP script.
回答1:
If they're static files, why not just include() them?
Forcing apache to make a subrequest seems like a waste.
If they're not really static, you can always construct a URL and use file_get_contents() to make a loopback request.
<?PHP
$include_me = '/some/dynamic/script.php';
$content = file_get_contents($include_me);
echo $content;
回答2:
In the end I actually found out a way to do this by using the X-Sendfile Apache module. Sending a file is then easy as executing
header("X-Sendfile: $local_file");
exit();
来源:https://stackoverflow.com/questions/3438154/subrequest-for-php-cgi