How would I use 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?

Dani AI

Generated

Short answer: treat web.py as the Python/WSGI side and let a real HTTP server dispatch requests to the correct runtime. Running PHP or classic ASP inside a Python process is only a quick hack; the stable solution is to run PHP via its FastCGI/daemon (php-fpm) and run web.py as a WSGI app behind a WSGI server, with Apache or Nginx routing requests to each service. Classic ASP is a Windows/IIS technology — host it on IIS or port the app rather than trying to emulate it from a Linux/Python process.

’s subprocess idea is useful for quick experiments because it demonstrates how a Python process can invoke a PHP script, but it has clear limitations: every request spawns a new OS process (slow under load), CLI PHP behaves differently from PHP under a web server (different server vars and env), error handling and logging are harder, and it opens serious injection and permission risks unless inputs are strictly sanitized. For anything beyond toy tests, avoid spawning interpreters per request.

A practical, production-oriented plan:

  • Run web.py with a WSGI server (uWSGI, gunicorn, etc.) managed by systemd or supervisor.
  • Run PHP with php-fpm (a managed FastCGI worker pool).
  • Put Nginx/Apache in front: serve static files directly, proxy Python routes to the WSGI socket/port, and forward .php requests to the php-fpm socket.
  • Keep services under separate users, enable timeouts, capture stderr to logs, and use absolute paths for binaries and sockets.

Troubleshooting checklist (common gaps seen here): check executable permissions and full paths, verify whether PHP is being run as CLI versus FPM, inspect webserver error and access logs, confirm socket ownership/permissions, add request timeouts, and never pass raw user input to shell commands. For forum placement: Web Development is the right place for architecture questions; use the PHP forum for deep PHP-fpm tuning and a Windows/IIS forum for classic ASP specifics. Thanks to for the working experiment and to for the question that prompted the discussion.

Recommended Answers

All 2 Replies

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.