The PHP server extension allows Virtuoso to execute PHP (v4) pages stored in the file system or in Virtuosos WebDAV repository. PHP pages run inside the Virtuoso process.
![]() |
Figure: 12.8.1. The HTTP PHP handler |
The VSE __http_handler_php() has been implemented so that the file extension '.php' is recognized by Virtuoso to switch between 'normal' mode and extension processing for PHP mode in the HTTP/WebDAV services.
PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used Open Source general-purpose scripting language that is suited for Web-based development. Here is an example of a simple PHP page:
<html> <head> <title>Example</title> </head> <body> <?php echo "Hi, I'm a PHP script!"; ?> </body> </html>
Notice how this is similar to VSP script, and different from a script written in other languages like Perl or C -- instead of writing a program with lots of commands to output HTML, you write an HTML script with some embedded code to do something. The PHP code is enclosed in special start and end tags that allow you to jump into and out of "PHP mode".
The Virtuoso distribution may already contain a binary executable of the PHP extension of the Virtuoso's Web Service. In which case you may skip the build process and start the server with the PHP extensions instead of starting the normal virtuoso server executable.
To start and test the Virtuoso server with the PHP extension do the following:
Make a simple file 'info.php' and place it in the HTTP root directory. The content of the info.php file should be the single line:
<?phpinfo();?>
This function produces an HTML page containing various PHP processor information.
Windows users will need to install the php4ts.dll (from the php.net site) before running the PHP enabled Virtuoso server. This DLL must be in the system path when Virtuoso starts and can typically be placed in the %SYSTEMROOT% directory without any path modifications.
The PHP library used with Virtuoso must be version 4.3.1 or greater. From this version the PHP library includes a serious PHP CGI vulnerability fix, without which the Virtuoso server will fail to start for security reasons.
The following functions have been added to the Virtuoso server in order to enable PHP processing.
This function will be detected and called automatically by the Virtuoso HTTP/WebDAV server when a request for a file with extension .php is made.
This function takes a string containing PHP code (page), and parameters supplied in the params array and returns the result from the PHP engine as a string. This can be useful for performing PHP transformations in PL or VSP code.
Unless the examples are shown as executed in the ISQL tool, this can be made also in the Virtuoso/PL code.
SQL> select php_str ('<?php echo "Hello World"?>'); callret VARCHAR _______________________________________________________________________________ Hello World SQL> select php_str ('<?php print abs (-1);?>'); callret VARCHAR _______________________________________________________________________________ 1 SQL> set MACRO_SUBSTITUTION off; SQL> select php_str ('<?php echo $a?>', 'a=Hello+World'); callret VARCHAR _______________________________________________________________________________ Hello World SQL> select php_str ('<?php echo $a?>', vector ('a', 'Hello World')); callret VARCHAR _______________________________________________________________________________ Hello World SQL> select php_str ('<?php echo "$a $b"?>', 'a=Hello+World&b=Hello+Again+World'); callret VARCHAR _______________________________________________________________________________ Hello World Hello Again World SQL> select php_str ('<?php $a=1; $b=2; $c=3; $d=$a+$b+$c; echo $d?>'); callret VARCHAR _______________________________________________________________________________ 6 SQL> select php_str ('<?php $a=8; $b=4; $c=8; echo $a|$b&$c?>'); callret VARCHAR _______________________________________________________________________________ 8
This is test how the PHP processor can instruct the HTTP server to send a custom response and header to the user agent. The following page can stored on the file system or in the WebDAV repository (in which case execution rights must be enabled). Hitting that page will redirect user-agent to the index.html page in HTTP server root.
<?php header ("HTTP/1.1 302 Found"); header ("Location: /index.html"); ?>
Previous
Blogging & Weblogs |
Chapter Contents |
Next
Deploying JSP Applications |