How to call PHP preprocesser
I have written a web server that servers html,js,css,images etc using C. I want to develop it that it has the capability to ser开发者_开发技巧ver PHP content also.
In that case I think I want to pass the PHP content to PHP preprocesser dynamically. How to call the PHP preprocesser.( I am using Ubuntu)
The easiest way is to invoke the PHP-CGI binary and communicate with that. Here is an example implementation in PHP, but it's quite simple in C as well:
- http://nanoweb-instant.googlecode.com/svn/trunk/modules/mod_cgi.php (advisable)
- http://nanoweb-instant.googlecode.com/svn/trunk/modules/mod_fcgi.php (avoid)
FastCGI is indeed faster, but is a fugly procotol. So I would recommend to avoid it. (SCGI is nicer, but not available for PHP). If you really must, then look into http://www.fastcgi.com/drupal/node/5 for a readymade C-library for this purpose.
You could process the PHP file through the command line functions.
http://www.php.net/manual/en/features.commandline.options.php
I believe you would do; php -f <file>
I recommend you to implement the FastCGI protocol. PHP can be run as FastCGI, as well as other scripting languages. This makes it possible to have PHP processes running as daemons, which speeds up page access times compared to traditional CGI and commandline calls.
The best possible way to do this is to implement CGI or FastCGI, which PHP both supports
You could communicate with the PHP interpreter through FastCGI. This should perform better than calling php for each request.
精彩评论