Is the SSI parser written in PHP?

Well, that may sound a little crazy, but the bear is here with me for a moment.

I am working on a site where the standard is to use SSI to include page headers, footers and menus. Included files use SSI conventions to handle different browsers, some #include attachments, and some # set / # if tricks to highlight the current page in the menu. In other words, this is more than just #include directives in SSI.

I'm sure some might argue with aesthetics, but actually it works very well for static HTML.

Now the problem is: I would just “include” the same SSI header and footer files from my PHP scripts, while avoiding code duplication and maintaining a consistent look and feel. If PHP runs in a regular mod_php environment, I would be able to do this using the PHP virtual () function. Unfortunately, the site uses FastCGI / suexec to run PHP (so that each VirtualHost can work as a different user), and this violates virtual ().

I use a fairly simple SSI parser that I wrote in PHP (it processes #includes and some really simple #if instructions), but I would like to get a more general solution. So, before I go crazy and write some probably buggy, more complete SSI parser, does anyone know about a full SSI parser written in PHP? Naturally, I am also open to other solutions that work under the limitations that I have outlined.

Thanks so much for your time.

+6
php apache ssi
source share
2 answers

Take a look at ESI: http://en.wikipedia.org/wiki/Edge_Side_Includes

You can create PHP proxies to handle them, this is HttpCache in Symfony2: https://github.com/fabpot/symfony/blob/master/src/Symfony/Component/HttpKernel/HttpCache/Esi.php

Or use HTTP proxies like Varnish, more efficient than Symfony2 ...

+2
source share

I understand this is an old question, but I ran into the same problem a few years ago, although with a perl implementation. I went ahead and unlocked the previous attempt and pretty successfully implemented the full apache emulator / parser (2.2.22) mod_include as the perl module http://search.cpan.org/dist/CGI-apacheSSI/lib/CGI/apacheSSI.pm Soon after that I found apache output filters and realized how perfect the solution is for my needs. Basically, you can tell apache to parse the output of your script, as if it were a .shtml or .php file (or whatever). This way you can output SSI markup from a perl or php (or something else) script and parse Apache. So you can do it (in the .htaccess file):

 AddOutputFilter INCLUDES .cgi 

This is for regular cgi files, but be careful, it adds a lot of overhead for all .cgi executable files, so what I actually do is create a special extension so that it runs as cgi, after which its result is parsed. without the overhead added to regular cgi files:

 <Files ~ ".pcgi$"> Options +SymLinksIfOwnerMatch +Includes AddOutputFilter INCLUDES .pcgi </Files> 

for php you can just do something like:

 <Files ~ ".pphp$"> Options +SymLinksIfOwnerMatch +Includes AddOutputFilter INCLUDES .pphp </Files> 

and that should do the trick! Hope someone helps there.

+1
source share

All Articles