Subrequest for PHP-CGI

被刻印的时光 ゝ 提交于 2019-12-12 01:28:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!