All you need is this this (except for windows) in a model (php.py?):
from subprocess import Popen, PIPE
import sys, os, threading
def runphp(source):
PHP_BIN = '/usr/bin/php'
PHP_ARGS = ['-q']
PHP_IN_SHELL = True
php = Popen([PHP_BIN,] + PHP_ARGS, shell=PHP_IN_SHELL,
bufsize=1<<12, universal_newlines=True, ## restriction of
templates
stdin=PIPE, stdout=PIPE, #stderr=PIPE,
close_fds= True)
php.stdin.write(source)
php.stdin.close()
page = php.stdout.read()
php.stdout.close()
return page
than in web2py
def index():
return runphp(response.render('theview.html',a=1,b=2,c=3))
theview.html will first be processed as a web2py template and then as
a php template. Mind that it is slow. For every page it create a new
process.
I did not try and I may have typos but should work.
Massimo
On Dec 30, 12:03 am, John-Kim Murphy <[email protected]> wrote:
> I have been thinking about how to run PHP on top of Web2Py. I'm interested
> in doing this because I want to augment an existing PHP app via Web2Py (For
> example, use the T() internationalization object; use Web2Py's auth access
> control). Also it will be easier to port a PHP application to Web2Py one
> piece at a time if the rest of the unported application can run as PHP.
>
> Something similar was done with
> Django<http://code.djangoproject.com/ticket/2440>: the
> PHP-based PmWiki <http://www.pmwiki.org/wiki/Main/WikiSandbox?action=edit> and
> even WordPress were integrated with
> Django<http://showmedo.com/videotutorials/video?name=pythonNapleonePyConTech...>.
> I've been studying the Python source
> code<http://code.djangoproject.com/attachment/ticket/2440/php.py>,
> and it looks like this could be used to render PHP from a Web2Py view. I'm
> trying to imagine how this would fit into Web2Py; perhaps distributed as a
> plugin:
>
> 1. The PHP code should not be aware it is running on top of Web2Py. Any
> Web2Py template language is expanded before being sent to the PHP parser.
> (I
> just watched the video, and it provides some more details. It looks like
> the
> PHP files had to be modified a bit, which I was trying to avoid, if
> possible.)
> 2. The PHP files (possibly with some {{Web2Py template code}} added) seem
> like views, but a PHP application will not have any associated Web2Py
> actions. Should there be a Web2Py controller that manages requests for PHP
> content, picking the correct PHP file based on the request? Should the PHP
> files just reside in a new, special php directory?
> 3. How are POST, GET, and SESSION variables passed to/from PHP? It seems
> PHP sessions are stored on the server; not sure about POST and GET...
> PmWiki
> uses URL variables, so I think they are being passed somehow.
>
> Any insights from people more familiar with Web2Py, PHP, and/or Django much
> appreciated!
>
> John