How would I use web.py to execute ASP/PHP server files?
Or can web.py not do that and can someone provide me a python script that can execute ASP/PHP server files?
Should I try posting this in the PHP forum, Web Design, html, and css fourm, or the Web development forum if I don't get an awnser here?

The correct solution would be to serve web.py as fastcgi together with PHP and ASP, this should be managed by a server as Apache or Nginx. But if you want to try the built in server you could do something like this:

#!/usr/bin/env python

import web
from subprocess import check_output

urls = (
    '/', 'index',
    '/reverse', 'reverse'
)

class index:
    def GET(self):
        return "Hello, world!"

class reverse:
    def GET(self):
        x = web.input(arg1='')
        r = check_output(["./reverse.php", "%s" % x.arg1])
        return "Reverse of " + x.arg1 + " is " + r

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

Then as PHP script:

#!/usr/bin/env php
<?php

    echo strrev($argv[1]);

Make the php script executable:

chmod 755 reverse.php

Otherwise change this line:

r = check_output(["./reverse.php", "%s" % x.arg1])

With:

r = check_output(["/usr/bin/env php reverse.php", "%s" % x.arg1])

And then try the url:

http://localhost/reverse?arg1=hello

It should output olleh. Note mine is just a test, this is not good for production usage.

Docs:

Sorry for the update, I did a little error in my previous post, regarding the alternative to call the PHP executable. The correct version is this:

r = check_output(["/usr/bin/env", "php", "./reverse.php", "%s" % x.arg1])

Otherwise it will output an exception, I haven't noticed it before because I forgot to restart the server.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.