Viewed   81 times

For some reason, I have to run a php script to get an image from Python. Because the php script is very big and it is not mine, it will takes me days to find out the right algorithm used and translate it into python.

I am wonder if there is any way to run php script, with few parameters, which returns a image, in python.

 Answers

2

Example code:

import subprocess

# if the script don't need output.
subprocess.call("php /path/to/your/script.php")

# if you want output
proc = subprocess.Popen("php /path/to/your/script.php", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()
Monday, December 5, 2022
4

There is runkit, but you may find it simpler to just call the script over the command line (Use shell_exec), if you don't need any interaction between the master and child processes.

Monday, October 24, 2022
 
am_skp
 
5

Using PDO prepared statements:

$placeholders = str_repeat('?, ', count($array)-1) . '?';
$stmt = $pdo->prepare("SELECT * FROM table WHERE field IN ($placeholders)");
$stmt->execute($array);

$placeholders will contain a sequence of ?, ?, ? placeholders, with the same number of ? as the size of the array. Then when you execute the statement, the array values are bound to the placeholders.

Saturday, August 27, 2022
 
xorlev
 
4

No. When a process is killed, the operating system releases all operating system resources (memory, sockets, file handles, …) previously acquired by that process.

Sunday, September 18, 2022
 
vsb
 
vsb
3

Needless to say you should find another solution ASAP. In the meantime you can eval the code like this:

$str = '<h1>Welcome</h1><?php echo $motto?><br/>'; // Your DB content

eval("?> $str <?php ");

Demo: http://codepad.org/ao2PPHN7

I can't stress that enough: eval is dangerous, and application code shouldn't be in the database. Try a template parser like Smarty, Dwoo, or my favorite: Twig.

Wednesday, November 9, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :