Page 1 of 1

Pip - Running Python within PHP

Posted: Fri May 04, 2007 8:13 pm
by Jza
If anyone have tried to use mod_python, it knows the issues on configuring Python to develop for the web. However with this implementation you could run python code within PHP.

Unfortunately the extensions is very alpha and even if it's old it, the development hasn't been that fast. Actually is a bit stalled.

However here is a code sample:

Code: Select all

<?php
$a = "test";
$b = true;
$c = 50;
$d = 60.4;

$code = <<<EOD
import php

a = php.var('a')
b = php.var('b')
c = php.var('c')
d = php.var('d')

print a, b, c, d
print a, d / c + b, a
EOD;

py_eval($code);
?>
Result:

Code: Select all

test 1 50 60.4
test 2.208 test
What is worst it seem to only work on python 2.3 and php4.x. I havent seen a package for php5.