title: Call PHP code from Python
body: <p>I'm trying to integrate an old PHP ad management system into a (Django) Python-based web application. The PHP and the Python code are both installed on the same hosts, PHP is executed by <code>mod_php5</code> and Python through <code>mod_wsgi</code>, usually.</p>
  
  <p>Now I wonder what's the best way to call this PHP ad management code from within my Python code in a most efficient manner (the ad management code has to be called multiple times for each page)? </p>
  
  <p>The solutions I came up with so far, are the following:</p>
  
  <ol>
  <li><p>Write SOAP interface in PHP for the ad management code and write a SOAP client in Python which then calls the appropriate functions.</p>
  
  <p>The problem I see is, that will slow down the execution of the Python code considerably, since for each page served, multiple SOAP client requests are necessary in the background.</p></li>
  <li><p>Call the PHP code through os.execvp() or subprocess.Popen() using PHP command line interface.</p>
  
  <p>The problem here is that the PHP code makes use of the Apache environment ($_SERVER vars and other superglobals). I'm not sure if this can be simulated correctly.</p></li>
  <li><p>Rewrite the ad management code in Python.</p>
  
  <p>This will probably be the last resort. This ad management code just runs and runs, and there is no one remaining who wrote a piece of code for this :) I'd be quite afraid to do this ;)</p></li>
  </ol>
  
  <p>Any other ideas or hints how this can be done?</p>
  
  <p>Thanks.</p>