This is very interesting and could make me save (or waste) a lot of
time : I have to move a website from PHP to web2py.  The website is
small and not really dynamic : the content is in tables and so but the
site will be  extended (in web2py)  and can be see as a static website
(but with ugly urls with vars).  For some reasons I have to move it
"like that" to web2py quick (and dirty).  I had that way in mind:
- crawl and capture the whole site (not that big and then perfectly
feasible) and put everything in a the static folder of a web2py app.
- write a simple and generic controller function (or generate one
simple controller function per page).
- write a regex script to find and replace the <a href ...> tags in
order to use URL() in them.
- tweak the route.py file in order to keep the actual urls unchanged
(BTW, I could change the urls if this is done in a good way -this is
the only cleanliness requirement, all the rest can be ugly- for google
and if that's possible for bookmarkers : any hint ?)

It can be some work.  But now I read this thread about using PHP from
web2py. Maybe, that would be quickly done like that. I just don't want
to use any other webserver than web2py (apache or whatever) at this
time. The performance penalty is not an issue (the part of the site
that will remain in php is there for historical reasons and not
heavily used).

My main concerns about this way are:
- the complexity of having runphp working
- the work on the templates : I guess that I have to put the php
templates in the view folder but I don't see exactly what else I have
to do on them
- do I have to tweak routes.py ? in the same way as above ?

I would appreciate any insights about that.

On Dec 30, 7:42 am, mdipierro <[email protected]> wrote:
> 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
>
>

Reply via email to