2

I'm working on a python plugin & it needs to retrive some data from php script, As I tried below I can retrive php output as shell command,

But I need to call start() function from my python script by passing values as start(10,15)

Is there a possible way to call start() php function with parameters from python script ?

PHP Script:

<?php

function start($height, $width) {
    
    return $height*$width;
}

echo start(10,15);  // #1

?>

Python Script:

import subprocess

result = subprocess.run(
    ['php', './check1.php'],    # program and arguments
    stdout=subprocess.PIPE,  # capture stdout
    check=True               # raise exception if program fails
)
print(result.stdout)         # result.stdout contains a byte-string

1 Answer 1

2

You can pass command-line arguments to a PHP script. See https://www.php.net/manual/en/reserved.variables.argv.php

PHP:

...
echo start($argv[1], $argv[2]);

Python:

result = subprocess.run(
    ['php', './check1.php', '10', '15'],
    stdout = subprocess.PIPE,
    check=True
)
Sign up to request clarification or add additional context in comments.

3 Comments

hi Sir,if we have multiple functions like start1( ) ,start2( ) ,how can we select & pass values to specific function..
If your main code is in PHP, why not just run PHP? Why involve Python at all? You can certainly pass a "command" word as one of the arguments.
the reason was plugins which I try to implement based on python but core system which I try to retrieve data is PHP,anyway thank you for your comment sir,I found a way..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.