0

I am trying to call a PHP file residing on same server as my python script . I just started with python and are not aware of the basics . I have tried with

import subprocess 
 
subprocess.call("php /path/to/your/script.php") 

But its giving file now found error how ever when I execute php /path/to/your/script.php its executing properly.

Apart from above I have tried :

cmd = "php and your file name"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

and variant of subprocess but of no use, any help is much appreciated. I just need to call a PHP API along with some parameters i.e.

xyz.php?name=variable&age=variable2
4
  • Also Tried with subprocess.call(["php", "/path/file.php"]) its not giving any error but its not getting called as its not coming in access logs Commented Sep 14, 2020 at 14:03
  • If you call PHP CLI, it won't land in an access log, since it isn't routed via your httpd server. The only thing logged from the CLI would be errors (assuming correct setup). Commented Sep 14, 2020 at 15:17
  • Does this answer your question? 1:1 call PHP from Python ... looking at the examples there, it seems you're missing the [ ]; as in, need subprocess.call(['php', .... Commented Sep 14, 2020 at 15:17
  • Hi @MarkusAO Yes you are right , it wont land in CLI. Thanks for the clarification I tried emailing from the PHP file and its working as expected . I was previously searching in the logs but as you said it won't land in access logs. Commented Sep 28, 2020 at 5:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.