Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 874

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="12. Web Application Development" />
  <meta name="dc.subject" content="12. Web Application Development" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="webappdevelopment.html" title="Chapter Contents" />
  <link rel="prev" href="blogger.html" title="Blogging &amp; Weblogs" />
  <link rel="next" href="rthjsp.html" title="Deploying JSP Applications" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>12. Web Application Development</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="servphpext" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>12. Web Application Development</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="webappdevelopment.html">Chapter Contents</a> | <a class="link" href="blogger.html" title="Blogging &amp; Weblogs">Prev</a> | <a class="link" href="rthjsp.html" title="Deploying JSP Applications">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="webappdevelopment.html">Web Application Development</a>
   </div>
    <br />
   <div>
      <a href="webserver.html">The HTTP Server</a>
   </div>
   <div>
      <a href="wsacl.html">Web Services ACL (Access Control List)</a>
   </div>
   <div>
      <a href="vsp1.html">Virtuoso Server Pages (VSP)</a>
   </div>
   <div>
      <a href="vspx.html">Virtuoso Server Pages for XML (VSPX)</a>
   </div>
   <div>
      <a href="rthwritaspxapps.html">Deploying ASP.Net Web Applications</a>
   </div>
   <div>
      <a href="asmxhosting.html">ASMX Web Service Hosting</a>
   </div>
   <div>
      <a href="blogger.html">Blogging &amp; Weblogs</a>
   </div>
   <div class="selected">
      <a href="servphpext.html">Deploying PHP Applications</a>
    <div>
        <a href="#serverphpbuild" title="Building the Virtuoso Server With PHP Extension">Building the Virtuoso Server With PHP Extension</a>
        <a href="#serverphpinc" title="PHP Extension Functions">PHP Extension Functions</a>
        <a href="#serverphpexamples" title="PHP Examples">PHP Examples</a>
    </div>
   </div>
   <div>
      <a href="rthjsp.html">Deploying JSP Applications</a>
   </div>
   <div>
      <a href="perlhosting.html">Perl Hosting</a>
   </div>
   <div>
      <a href="pythonhosting.html">Python Hosting</a>
   </div>
   <div>
      <a href="rubyhosting.html">Ruby Hosting</a>
   </div>
    <br />
  </div>
  <div id="text">
<a name="servphpext" />
    <h2>12.8. Deploying PHP Applications</h2>

<p>The PHP server extension allows Virtuoso to execute PHP (v4) pages
stored in the file system or in Virtuoso&#39;s WebDAV repository.   PHP pages run inside the Virtuoso process.</p>

<table class="figure" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td>
          <img alt="The HTTP PHP handler" src="../images/http_handler_php.jpg" />
     </td>
    </tr>
    <tr>
        <td>Figure: 12.8.1. The HTTP PHP handler</td>
    </tr>
    </table>

<p>
The VSE __http_handler_php() has been implemented so that the file
extension &#39;.php&#39; is recognized by Virtuoso to switch between &#39;normal&#39; mode and
extension processing for PHP mode in the HTTP/WebDAV services.</p>

<p>PHP (recursive acronym for &quot;PHP: Hypertext Preprocessor&quot;) 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:</p>

<a name="ex_phpintro" />
    <div class="example">
      <div class="exampletitle">PHP introductory example</div>

<div>
        <pre class="programlisting">
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Example&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;

        &lt;?php
        echo &quot;Hi, I&#39;m a PHP script!&quot;;
        ?&gt;

    &lt;/body&gt;
&lt;/html&gt;
</pre>
      </div>
</div>

<p>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 &quot;PHP mode&quot;.</p>

<div class="tip">
      <div class="tiptitle">See Also:</div>
  <p>
        <a href="http://www.php.net/docs.php">PHP Online Documentation</a>
      </p>
  <p>
        <a href="inprocess.html">In-Process Data Access Client</a>
      </p>
    </div>

<a name="serverphpbuild" />
    <h3>12.8.2. Building the Virtuoso Server With PHP Extension</h3>

<ol>
      <li>
Firstly you need to have the PHP4 library installed with Zend and ODBC interface enabled.
On UNIX-es this can be enabled by doing &#39;configure --enable-experimental-zts --with-iodbc&#39;.
On Windows the library must be downloaded from the <a href="http://www.php.net/">php.net</a> site.
</li>
      <li>
Make sure that the iODBC library is installed if you are preparing to build on UNIX platform.
</li>
      <li>
Make the bif_server_php executable in the bifsdk/examples/ directory.  This same directory
contains the source file for the bif_server_php executable: bif_server_php.cpp.
</li>
    </ol>

<p>
The Virtuoso distribution may already contain a binary executable of the
PHP extension of the Virtuoso&#39;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.
</p>

<p>
To start and test the Virtuoso server with  the PHP extension do the following:
</p>

<ol>
      <li>
<p>
Make a simple file &#39;info.php&#39; and place it in the HTTP root directory.
The content of the info.php file should be the single line: </p>
<div>
          <pre class="programlisting">
&lt;?phpinfo();?&gt;
</pre>
        </div>
<p>
This function produces an HTML page containing various PHP processor information.
</p>
</li>
      <li>
Start the server.  For Linux platform: bif_server_php -f, for Windows
platform: bif_server_php-odbc-t.exe -f</li>
      <li>
Test the installation by entering the http://[host:port]/info.php as the
URL of a browser of your choosing.
</li>
    </ol>

<div class="note">
      <div class="notetitle">Note:</div>
<p>Windows users will need to install the php4ts.dll (from the
<a href="http://www.php.net/">php.net</a> 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.</p>
</div>

<div class="note">
      <div class="notetitle">Note:</div>
<p>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.</p>
</div>

<br />


<a name="serverphpinc" />
    <h3>12.8.3. PHP Extension Functions</h3>

<p>
The following functions have been added to the Virtuoso server in order to enable PHP processing.
</p>

<a name="fp_phphandlerfunction" />
    <div class="formalpara">
      <strong>PHP Server Handler</strong>


  <div class="funcsynopsis">
        <a name="fproto_http_handler_php" />
    <span class="funcdef">
      <span class="function">__http_handler_php</span>
      </span>
    (<span class="paramdef">in <span class="parameter">file_name</span> varchar</span>, 
    <span class="paramdef">in <span class="parameter">params</span> vector (opt1, value [,...]) or string session</span>, 
    <span class="paramdef">in <span class="parameter">lines</span> vector (opt, value[,...] )</span>, 
    <span class="paramdefoptional">[inout <span class="optional">what</span> any]</span>);
  </div>


<p>
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.
</p>

<ul>
<li>
The <strong>file_name</strong> argument will be the path to the file when the PHP page is stored on the
file system or the actual content of the page when a WebDAV resource is processed.
</li>
<li>
The content of request entity body will be stored in a string session
and passed down to the __http_handler_php as the <strong>params</strong> argument.
</li>
<li>
The HTTP request header will be passed as the <strong>lines</strong> argument.
</li>
<li>
The <strong>what</strong> parameter is used for in two ways: to indicate whether the first argument is a
path/file name to a file on the filesystem or the content of the required WebDAV resource.
The HTTP/WebDAV server will return an array of two elements to this parameter.
</li>
</ul>
</div>

<a name="fp_phpinlineprocessor" />
    <div class="formalpara">
      <strong>PHP Processor</strong>


  <div class="funcsynopsis">
        <a name="fproto_php_str" />
    <span class="funcdef">
      <span class="function">__http_php_str</span>
      </span>
    (<span class="paramdef">in <span class="parameter">string</span> varchar</span>, 
    <span class="paramdef">in <span class="parameter">params</span> vector (opt1, val1 [,...]) , varchar</span>);
  </div>


<p>
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.
</p>

<ul>
<li>the <strong>string</strong> is the source of the PHP page</li>
<li>
          <strong>params</strong> is a string or array of strings containing parameter
name and parameter value pairs.  In the case of a single string it must contain form
parameters in the application/x-www-form-urlencoded encoding.
In case of an aref of strings it must contain the name and value for parameters.
(Like the params argument in the VSPs).
</li>
</ul>
</div>
<br />

<a name="serverphpexamples" />
    <h3>12.8.4. PHP Examples</h3>
<a name="ex_serverphpstr" />
    <div class="example">
<div class="exampletitle">Examples of the php_str() usage</div>

<p>
Unless the examples are shown as executed in the ISQL tool, this can be made also in the Virtuoso/PL code.
</p>

<div>
        <pre class="programlisting">

SQL&gt; select php_str (&#39;&lt;?php echo &quot;Hello World&quot;?&gt;&#39;);
callret
VARCHAR
_______________________________________________________________________________

Hello World

SQL&gt; select php_str (&#39;&lt;?php print abs (-1);?&gt;&#39;);
callret
VARCHAR
_______________________________________________________________________________

1

SQL&gt; set MACRO_SUBSTITUTION off;
SQL&gt; select php_str (&#39;&lt;?php echo $a?&gt;&#39;, &#39;a=Hello+World&#39;);
callret
VARCHAR
_______________________________________________________________________________

Hello World

SQL&gt; select php_str (&#39;&lt;?php echo $a?&gt;&#39;, vector (&#39;a&#39;, &#39;Hello World&#39;));
callret
VARCHAR
_______________________________________________________________________________

Hello World

SQL&gt; select php_str (&#39;&lt;?php echo &quot;$a $b&quot;?&gt;&#39;, &#39;a=Hello+World&amp;b=Hello+Again+World&#39;);
callret
VARCHAR
_______________________________________________________________________________

Hello World Hello Again World

SQL&gt; select php_str (&#39;&lt;?php $a=1; $b=2; $c=3; $d=$a+$b+$c; echo $d?&gt;&#39;);
callret
VARCHAR
_______________________________________________________________________________

6

SQL&gt;  select php_str (&#39;&lt;?php $a=8; $b=4; $c=8; echo $a|$b&amp;$c?&gt;&#39;);
callret
VARCHAR
_______________________________________________________________________________

8

</pre>
      </div>
</div>


<a name="serverphpredir" />
    <div class="example">
<div class="exampletitle">Examples of the php redirect page</div>

<p>
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.
</p>

<div>
        <pre class="programlisting">
&lt;?php
  header (&quot;HTTP/1.1 302 Found&quot;);
  header (&quot;Location: /index.html&quot;);
?&gt;
</pre>
      </div>
</div>

<br />

<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="blogger.html" title="Blogging &amp; Weblogs">Previous</a>
          <br />Blogging &amp; Weblogs</td>
     <td align="center" width="34%">
          <a href="webappdevelopment.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="rthjsp.html" title="Deploying JSP Applications">Next</a>
          <br />Deploying JSP Applications</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>