This is how I do it. It works like a charm.
def php(code):
p = Popen(['php'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, close_fds=True)
o = p.communicate(code)[0]
try:
os.kill(p.pid, signal.SIGTERM)
except:
pass
return o
To execute a specific file, follow these steps:
width = 100
height = 100
code = """<?php
include('/path/to/file.php');
echo start(""" + width + """, """ + height + """);
?>
"""
res = php(code)
source
share