views:

29

answers:

1

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.

A: 

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;
timdev
I can't include or read-echo them, most importantly, because in that way I don't get Apache to set all the HTTP headers for me. Besides, for static large files, your method is quite inefficient.
CAFxX
p.s. Rereading my initial post I realized that the fact that I needed the headers to be set by Apache was not clear. Sorry about that.
CAFxX
What headers do you think apache is going to send? I think you're confused about what virtual() actually does. The way I read the docs, using virtual() on static files is worthless, and just creates unnecessary overhead.
timdev
I'm talking about the HTTP headers that Apache sets automatically like Content-Type, ETag, Last-Modified, the client cache control headers, etc.The documentation is not wonderfully clear on this point, but some of the comments to the php virtual() function documentation imply this (see e.g. vcaron at bearstech dot com).
CAFxX
But anyway, let's suppose that virtual() is not well suited for this. How would you do this? As I said, right now I redirect the browser to a different URL. Is there a way for a PHP script to tell Apache "look, you asked me to produce the page X but actually its contents are cached in static page Y, serve that instead".
CAFxX
Alright, I stand corrected. The bit in the docs about apache flushing output buffer and any buffers made me think that virtual() would not output headers associated with the sub-request. If that comment is to be believed, it does (at least if you don't output anything before the call to virtual()). The best solution I can think of for static files is to manually set headers and readfile() the static file.
timdev